NSDateFormatter은 날짜, 시간의 간격을 포맷입니다. 이를 수행하는 더 좋은 방법은 타이머를 시작할 때 기록하는 것입니다. 매초마다 타이머를 시작한 이후 경과 한 시간을 레이블로 업데이트하십시오.
- (void)startTimer {
// Initialize timer, with the start date as the userInfo
repeatTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateLabel) userInfo:[NSDate date] repeats:YES];
}
- (void)updateLabel:(NSTimer *)timer {
// Get the start date, and the time that has passed since
NSDate *startDate = (NSDate *)[timer userInfo];
NSTimeInterval timePassed = [[NSDate date] timeIntervalSinceDate:startDate];
// Convert interval in seconds to hours, minutes and seconds
int hours = timePassed/(60 * 60);
int minutes = (timePassed % (60 * 60))/60;
int seconds = ((timePassed % (60 * 60)) % 60);
NSString *time = [NSString stringWithFormat:@"%i:%i:%i", hours, minutes, seconds];
// Update the label with time string
}