我尝试本地化我的日期,但由于某些原因,它不能从区域输出正确的格式。
它是这样测试我的代码的:
if(dateformater==nil)
dateformater =[[NSDateFormatter alloc] init];
[dateformater setLocale:[NSLocale currentLocale]];
[dateformater setDateStyle:NSDateFormatterMediumStyle];
[dateformater setTimeStyle:NSDateFormatterShortStyle];
NSString *string_date=[dateformater stringFromDate:date];
NSLog(@"Loacle:----%@ Date:----%@",[[NSLocale currentLocale] localeIdentifier],string_date);这里有一些本地化日期的例子,以及哪里出了问题。
Loacle:----da_DK Date:----24/11/2011 14.10--------(WRONG)
Loacle:----en_BE Date:----24 Nov 2011 14:09--------(OK)
Loacle:----nl_BE Date:----24-nov.-2011 14:10------(WRONG)
Loacle:----fr_BE Date:----24 nov. 2011 14:11-------(OK)
Loacle:----en_US Date:----Nov 24, 2011 2:11 PM-----(OK)
Loacle:----en_GB Date:----24 Nov 2011 14:11--------(OK)需求表明,它应该在所有地区保持一致。
发布于 2011-11-24 16:58:31
如果您想要相同的输出,则需要使用相同的语言环境,或者使用setDateFormat:。拥有语言环境的全部意义在于为不同的风格提供不同的格式。
https://stackoverflow.com/questions/8254265
复制相似问题