I want to detect the time format change done in the system setting. I used following code but it always give me the time old format. How can i get new time format?
#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);
}
I'm not sure why you expect that the dateFormat changes if the date changes significantly.
The significant time change event is triggered when the time (i.e.
[NSDate date]
) changes. For example if a new day starts, if the user changes timezone or if daylight-saving starts or ends.But those events don't change the date format.
I think you want to monitor locale changes. There is a notification for that:
NSCurrentLocaleDidChangeNotification
.Something like this should work:
j
is a template that will be replaced withh a
(12 hour format) orH
(24 hour format) by the date template method