我的倒计时有一点问题,事实上一切正常,但时间格式不正确,也就是说,它告诉我这个:
03:94:20:38
但我会在我看来真正倒计时的时间:
03:22:20:38
我的代码:
- (void)updateCounter:(NSTimer *)tmr
{
self.dateContest.hidden = NO;
NSTimeInterval iv = [self.date timeIntervalSinceNow];
int d = iv / 86400;
int h = iv / 3600; // My problem
int m = (iv - h * 3600) / 60;
int s = iv - h * 3600 - m * 60;
self.dateContest.text = [NSString stringWithFormat:@"%02d:%02d:%02d:%02d", d, h, m, s];
if (d + h + m + s <= 0) {
[tmr invalidate];
}
}
答案 0 :(得分:1)
你必须减去当天的工作时间
int d = iv / 86400;
int h = (iv / 3600) - (d * 24);
int m = (iv - (h + d * 24) * 3600) / 60
int s = lroundf(iv) % 60