How can we find the time format (whether 12 hours or 24 hours) mode in iPhone?
Asked
Active
Viewed 238 times
1 Answers
2
Check this answer by Micheal Waterfall in this previous SO question Detect whether iPhone is displaying time in 12-Hour or 24-Hour Mode?
@implementation NSLocale (Misc)
- (BOOL)timeIs24HourFormat {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterNoStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
NSString *dateString = [formatter stringFromDate:[NSDate date]];
NSRange amRange = [dateString rangeOfString:[formatter AMSymbol]];
NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]];
BOOL is24Hour = amRange.location == NSNotFound && pmRange.location == NSNotFound;
[formatter release];
return is24Hour;
}
@end
Hope this helps