开发者

Help needed in a calendar based app

开发者 https://www.devze.com 2023-02-11 14:50 出处:网络
I am creating a calendar based app. I have two dates say present date, and future date(due date), now i need to show the difference between these two dates in terms of days, hours, minutes & seco

I am creating a calendar based app.

I have two dates say present date, and future date(due date), now i need to show the difference between these two dates in terms of days, hours, minutes & seconds and i want to show a timer which will conti开发者_运维技巧nues to decrement second by second as the time increases and ultimately reaches to zero when due date comes.Basically it will be showing that how much days, hrs and seconds are left for the event.

How can I do that, please help me.

It would be a great help if i can get a similar kind of sample code.

Many Thanks in advance. iPhone Developer


Maybe It can be helpful to you - http://blog.webscale.co.in/?p=244


Basically you want to use NSTimeInterval and NSDate to calculate the difference in time. For example:

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM/dd/yyyy"];

NSDate *now = [NSDate date];
NSDate *futureDate = [dateFormat dateFromString:@"07/15/2015"];

// Now we can calculate the time interval, which really is an integer
// This is the number of seconds between the 2 dates, so with math you can calculate
// what you need.  Remember, when you do dateFromString, the time is midnight 00:00:00
// however, *now is set to the current time.  You may want to work on that a bit
NSTimeInterval timeDifference = [futureDate timeIntervalSinceDate:now];

// Also note, if you swap the order and do now timeIntervalSinceDate:futureDate, you
// get a negative number.
0

精彩评论

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

关注公众号