我有一个记录在控制台中的日期字符串:
2013年-8-11 10:00
我运行这个dateFormatter是为了使它成为一个NSDate:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm a"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"MST"]];
NSDate *openDate = [dateFormatter dateFromString:adjustedOpenDateString];
NSLog(@"DEALWITHTIMESTRINGS = open, now, close %@,%@,%@", openDate,[NSDate date], closeDate);但是,当我记录它时,openDate显示为NULL。closeDate也是。
发布于 2013-08-12 02:57:20
格式字符串中的hh:mm和a之间的空格可能导致其失败。
相反,您需要这样做:
[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mma"];https://stackoverflow.com/questions/18178960
复制相似问题