2012-07-03 39 views
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:57NSDateFormatter將不適用於1970年以前的日期嗎?

我的時區是倫敦,所以它應該返回3:59

這是因爲我們試圖格式化1970年以前的日期嗎?請確認是否有人知道。

回答

-5

在您的代碼中,您設置的時間間隔爲1970年。可能是因爲該.try不使用該設置,並設置URSELF的最短日期。

0

是的,正是這個原因。這是因爲時間戳的「開始」:

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

更多on wikipedia

相關問題