所以我有一个 NSTimer,我使用日期格式化程序来暂停和播放计时器,但是当我启动计时器时,它从 07:00:00 开始,而我希望它从 00:00:00 开始。
我的计时器代码是
-(void) updateTimer {
NSDate *currentDate = [NSDate date];
NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate];
NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"hh:mm:ss";
//[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
NSString *timeString = [dateFormatter stringFromDate:timerDate];
hhmmssLabel .text = timeString;
pauseTimeInterval = timeInterval;
}
-(void)pauseTimer {
[tickerTimer invalidate];
tickerTimer = nil;
[self updateTimer];
}
-(void) unPauseTimer {
startDate = [NSDate date] ;
startDate = [startDate dateByAddingTimeInterval:((-1)*(pauseTimeInterval))];
tickerTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/1.0 target:self selector:@selector(updateTimer) userInfo:nil repeats:YES];
}
我假设它与时区有关,所以我将其注释掉,这没有帮助。我无法让它在 00:00:00 开始