2012-01-28 111 views

回答

0

您要使用的功能從NSDate

例如:

//get time difference between someDate and now 
NSTimeInterval diff = [someDate timeIntervalSinceNow]; 

//get difference between dates 
NSTimeInterval diff2 =[someDate timeIntervalSinceDate: otherDate]; 

//comparing dates 
NSDate * earlierDate = [someDate earlierDate: otherDate]; 
NSDate * laterDate = [someDate laterDate: otherDate]; 
+0

謝謝你,我是幾乎沒有! – Eric 2012-02-03 20:58:15

0

如果你有可以作爲NSDate對象日期,你可以使用timeIntervalSinceDate:來計算秒的差別。

NSTimeInterval sinceThen = [firstDate timeIntervalSinceDate:[NSDate date]]; 

,這將給你的時間差爲NSTimeInterval這基本上是一個雙重指定的秒數。如果間隔爲負,則firstDate是以前,現在(這是[NSDate date]結果,否則它在未來。如果你的日期尚未NSDate形式,你可以使用一個NSDateFormatter做到這一點(See here, parsing date strings)

相關問題