objective-c - NSDateFormatter dateFromString :stringDate returning nil in iOS 8. 3

标签 objective-c xcode6 nsdateformatter ios8.3

我有这个代码

NSString *stringDate = @"2015-07-09 7:00 AM";
NSString *stringDateFormat = @"yyyy-MM-dd h:mm a";
NSTimeZone *timeZone =  [NSTimeZone localTimeZone];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter setTimeZone:timeZone];
[dateFormatter setDateFormat:stringDateFormat];
NSDate *dateFormatted = [dateFormatter dateFromString:stringDate];

现在的问题是dateFormatted 总是得到零值。当我在 Simulator iPhone5s 8.2 中尝试时是可以的,但是当我使用设备 iPhone5s 8.3 运行它时出现问题。

谁能帮我找出为什么 dateFormatted 的值是零?

最佳答案

这几乎是一个固定的回应但是:QA1480 .将格式化程序的区域设置为 en_US_POSIX,否则其行为将取决于用户的设置。

关于objective-c - NSDateFormatter dateFromString :stringDate returning nil in iOS 8. 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31317076/

相关文章:

objective-c - Swift 开关不适用于基于 C++ 的枚举

iphone - UIImageView 动画在最后一帧停止

ios - NSDateFormatter 字符串到日期的转换

iphone - 从字符串 '2011-08-16T19:03:21.000Z' 获取日期

objective-c - Mac - 获取电池/充电状态(插入或未插入)

ios - 如何使用 Objective C 在我的应用程序中获取联系人图像和电话号码

ios - 使用带有 SKScene 子类的 sks 文件

ios - 高度不明确的 UIView

swift - 如何在 Swift 中以字符串格式 "English"(不是 "en")显示当前语言?

ios - 从 UIDatePicker 中选择的日期与保存的日期不同