1

How can we find the time format (whether 12 hours or 24 hours) mode in iPhone?

enter image description here

Confused
  • 3,846
  • 7
  • 45
  • 72

1 Answers1

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

Community
  • 1
  • 1
visakh7
  • 26,380
  • 8
  • 55
  • 69