ios判断系统是24小时制还是12小时制/获取系统时间

//获取系统是24小时制或者12小时制

    NSString*formatStringForHours = [NSDateFormatterdateFormatFromTemplate:@"j" options:0 locale:[NSLocalecurrentLocale]];

    NSRange containsA =[formatStringForHours rangeOfString:@"a"];

    BOOL hasAMPM =containsA.location != NSNotFound;

//hasAMPM==TURE为12小时制,否则为24小时制


NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *now;
NSDateComponents *comps = [[NSDateComponents alloc] init];
NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |
                                         NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
now=[NSDate date];
comps = [calendar components:unitFlags fromDate:now];
week = [comps weekday];    
month = [comps month];
day = [comps day];
hour = [comps hour];
min = [comps minute];
sec = [comps second];

你可能感兴趣的:(ios,系统时间,12小时制)