【问题标题】:Change language for NSDate weekday and month更改 NSDate 工作日和月份的语言
【发布时间】:2013-03-16 08:11:16
【问题描述】:

我想显示这样的日期:第 7 个月的工作日。 我这样做了,并且语法正确。

NSDateFormatter* df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"EEEE dd MMMM"];
[df setTimeZone:[NSTimeZone localTimeZone]];

记录的结果是:3 月 16 日星期六。我只想拥有法国约会,而不是英国约会。我尝试设置本地时区,但没有任何改变。你知道如何做到这一点吗?

【问题讨论】:

    标签: ios objective-c nsdate nsdateformatter nstimezone


    【解决方案1】:

    使用标识符初始化语言环境。 您可以从

    获取所有可用的标识符
    [NSLocale availableLocaleIdentifiers];
    

    我相信@"fr_BI" 是法语标识符之一

    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"fr_BI"];
    [dateFormatter setLocale:locale];
    

    【讨论】:

    • 要选择合适的法语标识符,使用下面的代码: NSArray * bb = [NSLocale availableLocaleIdentifiers]; NSPredicate * bPredicate = [NSPredicate predicateWithFormat:@"SELF beginwith[c] 'fr'"]; NSArray * beginWithFr = [bb filteredArrayUsingPredicate:bPredicate]; for (NSString * elt in beginWithFr) { NSLog(@"%@ : %@",elt, [[[NSLocale alloc] initWithLocaleIdentifier:elt]localizedStringForLocaleIdentifier:elt]); }
    【解决方案2】:

    您使用适当的NSLocale 对象设置日期格式化程序的区域设置。

    此外,请注意此类硬编码日期格式。您的用户可能不喜欢以这种格式查看日期,因此您应该首先通过+[NSDateFormatter dateFormatFromTemplate:options:locale:] 运行格式字符串。 WWDC 2012 会议“国际化技巧和窍门”提供了大量关于此的有用信息。

    【讨论】:

      猜你喜欢
      • 2018-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-19
      • 2019-01-21
      • 1970-01-01
      • 2011-08-01
      • 2019-05-21
      相关资源
      最近更新 更多