我有将字符串转换为日期的函数。它工作得很好,但是当我尝试转换 20130331 时,应用程序崩溃了。这里是我的代码
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyyMMdd"];
NSDate *date = [dateFormat dateFromString:dateStr];
NSLog(@"before %@ dateStr %@",date,dateStr);
日志如下
2013-01-02 17:56:04.402 jana2ez[6067:11303] before 2013-03-28 22:00:00 +0000 dateStr 20130329
2013-01-02 17:56:04.498 jana2ez[6067:11303] before 2013-03-29 22:00:00 +0000 dateStr 20130330
2013-01-02 17:56:04.626 jana2ez[6067:11303] before (null) dateStr 20130331
任何想法??