iOS 获取当前时间并格式化为 MM-dd HH:mm:ss (Objective-C)
可以使用 NSDateFormatter 来格式化当前时间。
NSDate *currentDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:'MM-dd HH:mm:ss'];
NSString *formattedDate = [dateFormatter stringFromDate:currentDate];
NSLog(@'%@', formattedDate);
这将打印出当前时间的格式化字符串,格式为'MM-dd HH:mm:ss',例如'01-01 12:00:00'。
原文地址: https://www.cveoy.top/t/topic/qDHq 著作权归作者所有。请勿转载和采集!