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

run*_*mad 1 nsdate nsdateformatter ios ios6

我正在使用 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];
Run Code Online (Sandbox Code Playgroud)

谢谢!

jim*_*pic 6

可能是不同的本地化.在您的设备和模拟器上检查设置 - >常规 - >国际.您可以设置dateFormatter喜欢的区域设置

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en/US"];
[dateFormatter setLocale:locale];
Run Code Online (Sandbox Code Playgroud)