I have this code
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];
The problem now is dateFormatted keeps getting nil value. It is OK when I try it in Simulator iPhone5s 8.2 but, the problem occurs when I run it with device iPhone5s 8.3.
Can someone help me find why is dateFormatted is getting nil value?
It's almost a canned response but: QA1480. Set your formatter's locale to en_US_POSIX
or its behaviour will be dependent upon the user's settings.
来源:https://stackoverflow.com/questions/31317076/nsdateformatter-datefromstringstringdate-returning-nil-in-ios-8-3