Created
May 3, 2011 16:16
-
-
Save mwaterfall/953647 to your computer and use it in GitHub Desktop.
Determine whether iPhone is displaying 12 or 24 hour time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation NSLocale (Misc) | |
- (BOOL)timeIs24HourFormat { | |
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; | |
[formatter setLocale:self]; | |
[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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment