开发者

how to calculate diffrence b/w two dates in terms of mins/secs

i hav a two dat开发者_运维百科es of type nsdate and i want to calculate the diff b/w the two dates as a mins/seconds finally...

how can i do it..


NSDate has a -timeIntervalSinceDate: method.


EDIT

Therefore:

NSTimeInterval tval = [date1 timeIntervalSinceDate: date2];
int sec = tval % 60,
    min = tval - 60*sec;


So Alexsander want to say you take this:

double difference = [date1 timeIntervalSinceDate:date2] / 60;
The difference is now in minutes.


http://iphonedevelopment.blogspot.com/2009/07/category-on-nsdate.html

as you get the days you can convert into time.

But if you want exact difference , like if it is 1.5 days

you have to convert date into timestamp then find the difference

iPhone: Convert date string to a relative time stamp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜