标签:
1 NSDate *senddate=[NSDate date]; 2 NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init]; 3 [dateformatter setDateFormat:@"YYYYMMddHHmmss"]; 4 NSString *currenttime=[dateformatter stringFromDate:senddate];
上面是24小时制的。如果要改成12小时的H改成小写h.
判断获取系统时间是12小时还是24小时的代码如下:
NSString *formatStringForHours = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]];
NSRange containsA = [formatStringForHours rangeOfString:@"a"];
BOOL hasAMPM = containsA.location != NSNotFound;
//hasAMPM==TURE为12小时制,否则为24小时制
标签:
原文地址:http://www.cnblogs.com/crushing/p/4821805.html