我试图检测时间格式是12小时/ 24小时格式。基于这一点,我正在设置日历。
我用下面的代码在viewDidLoad方法中检测设备上的24小时格式。如何检测ipad sdk中的24小时时间格式
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setDateStyle:NSDateFormatterNoStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
NSString *dateString = [formatter stringFromDate:[NSDate date]];
NSRange amRange = [dateString rangeOfString:[formatter AMSymbol]];
NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]];
is24h = (amRange.location == NSNotFound && pmRange.location == NSNotFound);
之后我检查如下
if (is24h == TRUE) {
} else {
}
但我总是得到is24h值是假的。如果设备设置为12小时格式,我可以在日历中设置时间。但如果是24小时格式,我无法设置时间。
你能告诉我哪里需要改变。
这太神秘了。关心一个解释? – 2013-03-19 06:17:56