2010-05-31 117 views
0

我正在使用NSTimer,我正在努力顯示分鐘和秒鐘。但我對計算小時數所需的數學感到困惑。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]; 
} 

我應該使用什麼計算時間?

回答

1
seconds = ... 
seconds_in_minute = seconds % 60; 
minutes_in_hour = (seconds/60) % 60; 
hour_in_day = (seconds/3600) % 24;