【发布时间】:2014-02-24 06:28:18
【问题描述】:
我有一个 JSON 格式的日期字符串,如下所示:2014-02-07T00:00:00+08:00
我正在尝试将其转换为NSDate,格式为MM/dd/yyyy。
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"];
NSDate *date = [dateFormat dateFromString:datestring];
NSDateFormatter *newDateFormatter = [[NSDateFormatter alloc]init];
[newDateFormatter setDateFormat:@"MM/dd/yyyy"];
NSString *newString = [newDateFormatter stringFromDate:date];
NSLog(@"Date: %@, formatted date: %@", date, newString);
但结果为零。怎么了?
【问题讨论】: