2

我真的只想知道用户是否将iPhone设置为12小时模式进行时间显示。

NSLocale门课似乎在描述(用模糊的、不具体的术语,没有任何例子或明显有用的方法)我所追求的。

所以我创建了一些NSLocale像这样的对象:

NSLocale *systemLocaleApparently = [NSLocale systemLocale];
NSLocale *currentLocaleWithLotsOfGoodies = [NSLocale autoupdatingCurrentLocale];

当我使用调试器或检查这些对象时NSLog(),我能得到的最好的结果是:

<CFLocale 0x1278e0 [0x382084f8]>{type = system, identifier = ''} 

当前语言环境中有一个 ID 字符串,但没有其他内容。

从文档中,我可以从语言环境中查找值,其中之一是NSCalendar对象。所以我把它拿回来看了一下,它告诉我它是“gregorian”。

所有这些显然对某人有用......但我真正想要的是一个很好的大型属性字典,显示所有实际系统属性,主要是这样NSDateFormatters当用户选择 12 小时格式时我不会一直爆炸即使我已经强制格式化程序使用en_US_POSIX语言环境和固定setDate格式。

(我敢肯定NSCalendarDate从来没有遇到过这些问题......)

希望我明显遗漏了一些明显(并且可能令人尴尬)的东西,但也许有人会与我分享。请 :)

4

1 回答 1

3

这是判断用户是否将时间格式设置为 12 小时或 24 小时格式的一种方法:

NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
// Look for H (24-hour format) vs. h (12-hour format) in the date format.
NSString* dateFormat = [formatter dateFormat];
BOOL using24HourClock = [dateFormat rangeOfString:@"h"].location == NSNotFound;
于 2009-09-19T00:37:48.430 回答