【发布时间】:2016-01-12 12:58:02
【问题描述】:
我有一个以毫秒为单位的日期时间戳:
145146240000
我从那个时间戳创建一个 NSDate 对象:
NSTimeInterval seconds = [@"1451462400000" doubleValue] / 1000.0f;
NSDate *transactionDate = [NSDate dateWithTimeIntervalSince1970:seconds];
NSLog(@"%@", transactionDate);
我记录transactionDate的值:2015-12-30 08:00:00 +0000
然后我使用NSDateFormatter 输出这个日期:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"d MMMM YYYY"];
NSLog(@"%@", [dateFormatter stringFromDate:transactionDate]);
这错误地将年份输出为 2016!:
30 December 2016
这怎么可能?我的本地时区是 GMT+2,所以如果格式化程序解析它可能会延迟两个小时,但不是一整年!
【问题讨论】:
标签: ios objective-c nsdate nsdateformatter