我正在使用NSTimer,我正在努力显示分钟和秒。但我对计算小时数所需的数学感到困惑。
我正在使用:
- (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];
}
我应该在几个小时内使用什么计算?
答案 0 :(得分:1)
seconds = ...
seconds_in_minute = seconds % 60;
minutes_in_hour = ( seconds / 60 ) % 60;
hour_in_day = ( seconds / 3600 ) % 24;