tags:

views:

45

answers:

2

hi, all, I want know the passed time that also is between two date,

for example , dateTime1 and dateTime2 , I want a function like getPassedTime( time1, time2)

the function result should be like '1 day 3 hours 12 minutes 10 second' or just '40 second' ...

I know that the method 'timeIntervalSinceDate' of the class 'NSDate' can be use , but the problem is convert to details string that could be easy understand ....

anyone can help ? share some code will be appreciate or give me some tip if possible.

Thanks.

Regards

A: 

Use the timeIntervalSinceDate method of the NSDate class:

NSDate *date1 = [NSDate dateWithString:@"2001-03-24 10:45:32 +0600"];

NSDate *date2 = [NSDate dateWithString:@"2001-03-28 12:38:52 +0600"];

NSTimeInterval *timePassed = [date2 timeIntervalSinceDate:date1];
ennuikiller
Thanks a lots for your quick reply !
robin
A: 

You could use NSCalendar and NSDateComponents.

Code snippet in this thread.

Joost Schuur
Thanks a lots for your quick reply !
robin
You're welcome. Don't forget to upvote answers that you think are helpful, even if you've chosen them as the accepted answer too.
Joost Schuur