0
我正在研究Xcode中的一个应用程序,我想知道如何做到这一点:当我点击一个按钮,然后时钟显示在标签上时,它会保存文本(记录时钟)。文本字段/写日期内如何在点击按钮时节省文本时间?
我正在研究Xcode中的一个应用程序,我想知道如何做到这一点:当我点击一个按钮,然后时钟显示在标签上时,它会保存文本(记录时钟)。文本字段/写日期内如何在点击按钮时节省文本时间?
获取日期/显示日期对桌面文件:
- (IBAction)theButton:(id)sender {
NSString * currentDate = [[NSDate date] description];
[theLabel setStringValue:currentDate];
[currentDate writeToFile:@"/Users/Anne/Desktop/log.txt" atomically:YES encoding:NSUnicodeStringEncoding error:NULL];
}
结果:
2011-04-28 20点18分02秒+0200
获取时间/显示文本框内的时间/写入桌面文件的时间:
- (IBAction)theButton:(id)sender {
NSDate * now = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"hh:mm:ss"];
NSString *currentTime = [formatter stringFromDate:now];
[theLabel setStringValue:currentTime];
[currentTime writeToFile:@"/Users/Anne/Desktop/log.txt" atomically:YES encoding:NSUnicodeStringEncoding error:NULL];
}
结果:
8时十七分41秒
注意:您可以通过使用NSDateFormatter更改日期的任何格式。
只需要在uilabel outlet ... – Askapps 2011-04-28 18:20:47
我怎样才能得到日期呢? – Askapps 2011-04-28 18:20:55
再次感谢:) – Askapps 2011-04-28 18:22:35