我以为我最近看到了一些回答这个问题的东西,但现在我找不到它了。这里是我现在使用的代码来确定设置是否用于24小时时间显示。它在美国适用于我,但我不知道它是否适用于所有地区。这是足够的还是有更好的方法来找出当前的设置?如何确定iPhone是否设置为12小时或24小时时间显示?
+(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;
}
不错的3班轮。我想知道,“a”究竟代表什么?是否有可能一些神秘的设置可以将时间周期符号更改为“AM”?如果范围行改为' NSRange containsA = [formatStringForHours rangeOfString:@“a”options:NSCaseInsensitiveSearch];'? – Wienke
@Wienke“a”是AM/PM代号的ICU符号。它永远不可能是“A”,因为ICU使用“A”表示完全不同的事物(当天的毫秒数)。 –
+1,我觉得更舒服的搜索一个具有定义的固定含义的角色,并且不会根据语言环境而改变。 – DarkDust