0

我正在使用一个 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];
}

几个小时我应该使用什么计算?

4

1 回答 1

1
seconds = ...
seconds_in_minute = seconds % 60;
minutes_in_hour = ( seconds / 60 ) % 60;
hour_in_day = ( seconds / 3600 ) % 24;
于 2010-05-31T22:55:45.700 回答