Jak mogę ustalić, czy iPhone jest ustawiony na wyświetlanie czasu 12-godzinnego lub 24-godzinnego?
Pomyślałem, że ostatnio widziałem coś odpowiadającego na to, ale teraz nie mogę go znaleźć. Oto kod, którego używam teraz do określenia, czy ustawienia są wyświetlane przez 24 godziny. Działa dla mnie w USA, ale nie wiem, czy będzie działać we wszystkich lokalizacjach. Czy to wystarczy, czy jest lepszy sposób na ustalenie aktualnych ustawień?
+(BOOL) use24HourClock
{
BOOL using24HourClock = NO;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale: [NSLocale currentLocale]];
[dateFormatter setDateStyle:kCFDateFormatterNoStyle];
[dateFormatter setTimeStyle:kCFDateFormatterShortStyle];
// get date/time (1Jan2001 0000UTC)
NSDate* midnight = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate:0];
NSString* dateString = [dateFormatter stringFromDate: midnight];
// dateString will either be "15:00" or "16:00" (depending on DST) or
// it will be "4:00 PM" or "3:00 PM" (depending on DST)
using24HourClock = ([dateString length] == 5);
[midnight release];
[dateFormatter release];
return using24HourClock;
}