【发布时间】:2014-11-26 09:16:44
【问题描述】:
我想检测系统设置中的时间格式更改。我使用了以下代码,但它总是给我旧格式。如何获得新的时间格式?
#pragma mark
#pragma mark - application change time format
-(void)applicationSignificantTimeChange:(UIApplication *)application
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setDateStyle:NSDateFormatterNoStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setTimeZone:[NSTimeZone localTimeZone]];
NSString *dateString = [formatter stringFromDate:[NSDate date]];
NSLog(@"dataString ::%@",dateString);
NSRange amRange = [dateString rangeOfString:[formatter AMSymbol]];
NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]];
is12Hour = (amRange.length > 0 || pmRange.length > 0);
}
【问题讨论】:
标签: ios objective-c nsdate nsdateformatter nslocale