CocoaDev

Edit AllPages

I want to make a program that accurately counts down to a certain date specified by the user and shows the days, minutes, hours, and seconds until the day the countdown is supposed to end. Would the best way to do this be to use an NSTimer and have it fire every one second and then subtract the future date and time from the current date and time?

** Use (NSTimeInterval)timeIntervalSinceDate:(NSDate *)anotherDate, where anotherDate is the date of the event of your choice. Convert the result into a NSDate object and format it so you can see the seconds scroll down. Note that your timeInterval may be a negative number… **


Here’s an NSString category for converting seconds to either “X seconds/minutes/hours/days” or “HH:MM:SS” format:

This would be better implemented as an NSFormatter – perhaps even an NSDateFormatter? –JediKnil