Date
1 - 1 of 1
Determine System Time Format (12hr vs 24hr)
Sandor Szatmari
I have been using the following code to determine if a system is set to 12hr or 24hr time for sometime…
NSString *formatStringForHours = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]];
NSRange containsH = [formatStringForHours rangeOfString:@"H"];
BOOL shouldUse24HrTime = containsH.location != NSNotFound;
format = (shouldUse24HrTime) ? @"H:mm" : @"h:mm";
NSRange containsH = [formatStringForHours rangeOfString:@"H"];
BOOL shouldUse24HrTime = containsH.location != NSNotFound;
format = (shouldUse24HrTime) ? @"H:mm" : @"h:mm";
Now, on Catalina, I am realizing that this code is failing. Unfortunately, I don't know when this started to fail.
It always returns 'h a', whereas previously it returned 'H'.
macOS: 10.15.5 (19F101)Xcode: 11.6 (11E708)Deployment Target: 10.11Build SDK: 10.15
Is anyone else seeing the same thing? If others can confirm this same apparently errant behaviour I'll file a bug report. First, I want to be sure it's not just my system…
Also, does anyone know an alternative, or better, way to determine the time format of the system? ('Use 24-hour clock' as found in Date & Time System Preferences)
Thanks,
Sandor