NSLocale 大部分是空的 - 属性在哪里?

发布于 2024-08-05 00:13:58 字数 860 浏览 1 评论 0原文

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

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

因此,我创建了一些 NSLocale 对象,如下所示:

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

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

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

: locale 中有一个 ID 字符串,但没有其他内容。

从文档中,我可以从区域设置中查找值,其中之一是 NSCalendar 对象。所以我拿回来并查看它,它告诉我它是“公历”。

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

(我确信 NSCalendarDate 从来没有遇到过这些问题...)

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

I really just want to know whether the user has set the iPhone to 12 hour mode for time display.

The NSLocale class seemed to be describing (in vague unspecific terms without any examples or apparently useful methods) what I was after.

So I have created some NSLocale objects like so:

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

When I inspect these objects using the debugger or NSLog(), the best I can get is something along these lines:

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

The current locale has an ID string in it, but nothing else.

From the documentation, I can lookup values from the locale, and one of these is an NSCalendar object. So I get that back and have a look at it, and it tells me it is "gregorian".

All of which is apparently of use to somebody... but what I would really like is a nice big dictionary of attributes showing all of the actual system properties, mainly so that my NSDateFormatters don't keep blowing up when a user chooses 12 hour format even though I have forced the formatters to use en_US_POSIX locale and a fixed setDate format.

(I'm sure NSCalendarDate never used to have these problems...)

Hopefully I am missing something blatantly (and probably embarrassingly) obvious, but perhaps someone kind would share it with me. Please :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦罢 2024-08-12 00:13:58

以下是判断用户是否将时间格式设置为 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;

Here is one way to tell if the user has set their time format to a 12- or 24-hour format:

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文