NSTimer calculate hours
Posted
by Nic Hubbard
on Stack Overflow
See other posts from Stack Overflow
or by Nic Hubbard
Published on 2010-05-31T22:50:09Z
Indexed on
2010/05/31
22:53 UTC
Read the original article
Hit count: 308
I am using an NSTimer which I have working to show minutes and seconds. But I am confused about the math needed to calculate hours.
I am using:
- (void)updateCounter:(NSTimer *)theTimer {
static int count = 0;
count += 1;
int seconds = count % 60;
int minutes = (count - seconds) / 60;
// Not sure how to calculate hours
int hours = (count - minutes) / 60;
self.timer.text = [NSString stringWithFormat:@"%.2d:%.2d:%.2d", hours, minutes, seconds];
}
What calculation should I use for hours?
© Stack Overflow or respective owner