获取当前时间
NSDate * timeDate=[NSDate date];
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"HH:mm:ss"];
//[dateformatter setDateFormat:@"HH-mm-ss"];
NSString * locationString=[dateformatter stringFromDate:timeDate];
textField.text = locationString;
NSCalendar * cal=[NSCalendar currentCalendar];
NSUInteger unitFlags=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit;
NSDateComponents * conponent= [cal components:unitFlags fromDate:timeDate];
NSInteger year=[conponent year];
NSInteger month=[conponent month];
NSInteger day=[conponent day];
NSString * nsDateString= [NSString stringWithFormat:@"%4ld年%2ld月%2ld日",year,month,day];
textField.text = nsDateString;
本文介绍了如何使用Objective-C编程语言获取当前的时间和日期,并详细解释了使用`NSDate`和`NSDateFormatter`类的方法,包括设置日期格式以及如何将时间戳转换为易于阅读的字符串格式。
2万+

被折叠的 条评论
为什么被折叠?



