2012-10-25 41 views

回答

1

假設createdAt是UNIX時間戳,代碼爲:

NSTimeInterval createdAt = ...; 
NSDate *resultDate = [NSDate dateWithTimeIntervalSince1970:createdAt]; 

注意NSTimeIntervaldouble一個typedef,它存儲了多少秒時間,不像Java,所以沒有必要用1000乘以值;

1

呃......不知道「createAt」* 1000是什麼意思。當前日期和時間的1000倍?

在Objective C中可以使用:

  • (ID)initWithTimeIntervalSinceNow:(NSTimeInterval)秒

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html

創建日期時間對象具有偏移:

// creates a date time that is 1000 seconds away from the current time 
NSDate *date = [[NSDate alloc] initWithTimeIntervalSinceNow:1000]; 
+0

我明白了:)其他回答更清晰。所以+1仍然是:D –