代码之家  ›  专栏  ›  技术社区  ›  theLastNightTrain

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

  •  2
  • theLastNightTrain  · 技术社区  · 15 年前

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

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

    所以我创造了一些 纳斯拉尔 这样的对象:

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

    当我使用调试器或 NSLog() 我能得到的最好的东西就是这些线条:

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

    当前区域设置中包含ID字符串,但没有其他内容。

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

    所有这些显然对某人有用…但我真正想要的是一个显示所有实际系统属性的大字典,主要是为了 NSDateFormatters 当用户选择12小时格式时,即使我已经强制格式化程序使用,也不要一直放大。 en_US_POSIX 区域设置和固定 setDate 格式。

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

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

    1 回复  |  直到 9 年前
        1
  •  3
  •   Tyler    15 年前

    这里有一种方法可以判断用户是否已将时间格式设置为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;