模拟器上的NSDate格式正确,设备上的格式不正确

时间:2012-11-12 14:35:24

标签: ios ios6 nsdate nsdateformatter

我正在使用NSDateFormatter将日期格式化为相对日期。在模拟器中,日期显示为“2012年11月12日”,但在我的设备上,同一日期显示为“2012-11-12”。我正在运行相同的操作系统版本。

这是我正在使用的代码:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setDoesRelativeDateFormatting:YES];
NSString *dateString = [dateFormatter stringFromDate:dateToDisplay];

谢谢!

1 个答案:

答案 0 :(得分:6)

可能不同的本地化。检查设置 - >一般 - >您的设备和模拟器上的国际。您可以设置dateFormatter的区域设置

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en/US"];
[dateFormatter setLocale:locale];
相关问题