ios - NSDate格式在模拟器上正确,在设备上错误

标签 ios ios6 nsdate nsdateformatter

我正在使用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/

相关文章:

ios - Ionic Pro- iOS 构建代码签名

ios - 快速从 Realm 中提取值

iphone - 为 UITextView 添加轮廓/描边效果 ios <7

ios6 自动布局约束

xcode - 单元测试目标不在Xcode 4.5上运行

ios - 按日期参数过滤项目数组而不考虑时间

ios - NSDateFormatter 不识别时区

arrays - 在 Swift 中对 NSDate 对象的一维数组进行排序

ios - 查询当前用户信息

ios - 使用 SLRequest(无对话框)在 iOS 6 中将视频上传到 Facebook 的示例