gpt4 book ai didi

ios - NSDate 返回一个负的 NSTimeInterval

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:16:51 24 4
gpt4 key购买 nike

我有以下代码:

- (void)pointsStartedDisplaying {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
dispatch_async(dispatch_get_main_queue(), ^{
self.timeStartedDisplayingPoint = [NSDate date];
self.stopButton.enabled = YES;

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateElapsedTime:) userInfo:nil repeats:YES];
});
});
}

- (void)updateElapsedTime:(NSTimer *)timer {
NSTimeInterval elapsedTimeDisplayingPoints = [self.timeStartedDisplayingPoint timeIntervalSinceDate:[NSDate date]];
self.elapsedTimeValueLabel.text = [NSString stringWithFormat:@"%f seconds", elapsedTimeDisplayingPoints];
}

但是,elapsedTimeDisplayingPoints 的值非常准确,只是每次都是负值。为什么它会返回 -3、-4、-5、 等?

最佳答案

If the receiver is earlier than anotherDate, the return value is negative .你的例子就是这种情况。您可以使用 fabs() 获得正值。

关于ios - NSDate 返回一个负的 NSTimeInterval,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21488817/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com