I figured it out, its pretty easy. I just added this code to viewDidLoad
:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[NSLocale currentLocale]];
[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 is24h = (amRange.location == NSNotFound && pmRange.location == NSNotFound);
[formatter release];
NSLog(@"%@
",(is24h ? @"YES" : @"NO"));
And it perfectly returns YES
or NO
depending on the locale.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…