我有以下法文本,以图德洛德。 所有这些都正在每秒更新一个标签。 然而,当我管理这一法典时,它就看到了 du的文字,然后才看到了8个秘密,而不是9个。
因此,似乎像第9条那样容易确定这一点吗? 在我计算剩下的时间时,我是否应该把小数四舍五入?
感谢您的时间!
//Just dummy text
self.lblTime.text = @"Tid: 0h 0min 10sec";
NSDate *expireDate = [[NSDate alloc] initWithTimeInterval:10 sinceDate:[NSDate date]];
self.expires = expireDate;
[expireDate release];
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTimerDisplay) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:UITrackingRunLoopMode];
更新 时间变化
//Gets the time right now
NSDate *now = [NSDate date];
//Stores the difference in seconds between when the test was started and now.
NSTimeInterval interval = [self.expires timeIntervalSinceDate:now];
//Gets the number of hours
NSInteger hours = interval / 3600;
interval = (int)interval % 3600;
//Gets the number of seconds
NSInteger minutes = interval / 60;
interval = (int)interval % 60;
NSInteger seconds = interval;
//Updates the label
self.lblTime.text = [NSString stringWithFormat:@"Time: %dh %dmin %dsec", hours, minutes, seconds];