我有来自日期的字符串
formattedDateString: 2014-03-31 15:00:11
然后我用
NSDate *newDate = [dateFormatter dateFromString:formattedDateString];
我得到了
formattedDate 2014-03-31 12:00:11 +0000
我失去了3个小时。哪里不好?
完整代码
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[item[@"date"] doubleValue]];
// Divided by 1000 (i.e. removed three trailing zeros) ^^^^^^^^
NSString *formattedDateString = [dateFormatter stringFromDate:date];
NSDate *newDate = [dateFormatter dateFromString:formattedDateString];