【发布时间】:2013-12-31 13:36:34
【问题描述】:
我正在尝试从 nsdate 对象获取本地化的工作日
+ (NSString *)localizedWeekdayForDate:(NSDate *)date
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSString *language = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
dateFormatter.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"EEEE" options:0 locale:[NSLocale localeWithLocaleIdentifier:language]];
NSString *formattedDateString = [dateFormatter stringFromDate:date];
return formattedDateString;
}
语言字符串总是“en”……即使你的设备语言不是英语……我试过 [NSLocale currentLocale];以及preferedLanguages...这也行不通..
有什么建议吗?
【问题讨论】:
-
我认为您将语言与区域设置混淆了。像这样将语言环境绑定到设备语言是一个坏主意。例如;我的设备设置为英语,但我的区域格式(区域设置)是土耳其语。使用您的代码,我将始终使用美国日期格式。
-
正确...我现在使用的是regons格式
标签: ios nsdateformatter nslocale