开发者

Check if NSTimeInterval equals 0

//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];

if (interval == 0) {
    ...
}

Any reason why the condition wont be true?

Thanks.


Since NSTimeInterval is only a double, you might have floating point rounding error. Try using something like

if (abs(interval) < EPS) {

where EPS is a small enough constant.

Or, if you want to know seconds and not milliseconds, you can truncate that double to int.

But judging from your code, I think you might want to check if timeline has already expired, not that it expires at this exact moment. Probability of the later is very small. This should do the trick.

if (interval < 0) {
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜