Reputation: 209
I have a little problem with my countdown, in fact everything works fine but the hours are not in the right format that is to say, it shows me this:
03: 94: 20: 38
but I 'it would appear to me the real countdown of the hours that is to say:
03: 22: 20: 38
My code :
- (void)updateCounter:(NSTimer *)tmr
{
self.dateContest.hidden = NO;
NSTimeInterval iv = [self.date timeIntervalSinceNow];
int d = iv / 86400;
int h = iv / 3600; // My problem
int m = (iv - h * 3600) / 60;
int s = iv - h * 3600 - m * 60;
self.dateContest.text = [NSString stringWithFormat:@"%02d:%02d:%02d:%02d", d, h, m, s];
if (d + h + m + s <= 0) {
[tmr invalidate];
}
}
Upvotes: 0
Views: 52
Reputation: 2617
you have to minus that day hours as well
int d = iv / 86400;
int h = (iv / 3600) - (d * 24);
int m = (iv - (h + d * 24) * 3600) / 60
int s = lroundf(iv) % 60
Upvotes: 1