NSDate
在我的应用程序中,我使用此代码从以下位置创建NSString
:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyyMMddhhmmss"];
dateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:[NSTimeZone localTimeZone].secondsFromGMT];
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:comment.created];
NSLog(@"comment.created %@ dateFromString %@",comment.created, dateFromString);
但是对于某些字符串,它返回 null!
对于输入20131031083130
,它返回2013-10-31 04:31:30
,当20131107200617
-(null)
StreetJournal[32054:60b] comment.created 20131031083130 dateFromString 2013-10-31 04:31:30 +0000
StreetJournal[32054:60b] comment.created 20131107200617 dateFromString (null)
为什么?