我正在使用NSDateFormatter
将日期格式化为相对日期。在Simulator中,日期正确显示为“2012年11月12日”,但是在我的设备上,相同的日期显示为“2012-11-12”。我都运行相同的OS版本。
这是我正在使用的代码:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setDoesRelativeDateFormatting:YES];
NSString *dateString = [dateFormatter stringFromDate:dateToDisplay];
谢谢!
最佳答案
可能不同的本地化。在设备和模拟器上检查设置->常规->国际。您可以像这样设置dateFormatter
的语言环境
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en/US"];
[dateFormatter setLocale:locale];
关于ios - NSDate格式在模拟器上正确,在设备上错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13345597/