获取当前时间
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;
时间: 2024-12-10 16:18:02