1
double seconds = -62167464057.000;
NSDate *oldDate = [NSDate dateWithTimeIntervalSince1970:seconds];
MELog("oldDate = %@", oldDate);//oldDate = 0002-12-29 03:59:03 +0000

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init]  autorelease];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];

NSString *formattedDateString = [dateFormatter stringFromDate:oldDate];
NSLog(@"formattedDateString = %@", formattedDateString);//formattedDateString = 3:57 AM

在上面的代码中,日期组件的时间是 3:59,但是当我们格式化它以提取时间字段时,我们得到 3:57

我的时区是伦敦,所以它应该返回 3:59

这是因为我们试图格式化 1970 年之前的日期吗?请确认是否有人知道。

4

2 回答 2

0

是的,这正是原因。这是因为时间戳的“开始”:

Unix time, the number of seconds since 00:00:00 UTC on January 1, 1970

更多关于维基百科

于 2014-04-11T09:48:24.780 回答
-5

在您的代码中,您将时间间隔设置为 1970 年。可能是因为那个。尽量不要使用它,并由您自己设置最小日期。

于 2012-10-11T05:47:45.817 回答