iOS - 如何比较两次? [英] iOS - how to compare two times?

查看:45
本文介绍了iOS - 如何比较两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下函数来检查消息是否已过期 -

I use the following function to check if a message has expired -

- (BOOL) hasExpired:(NSDate*)myDate
{     
    if(myDate == nil)
    {
        return false;
    }
    NSDate *now = [NSDate date];
    return !([now compare:myDate] == NSOrderedAscending);
}

如果我比较两个不同的日期,这很好用.但是,如果消息在今天早些时候过期,则返回 false.关于如何修复它的任何想法?

This works fine if I am comparing two different dates. However, it returns false if the message has expired earlier in the day today. Any ideas on how I might fix it?

推荐答案

(添加我的评论作为答案:)

这不应该发生,NSDate 实例之间的 1 秒差异也足够了.添加带有两个日期的 NSLog() 以查看它们是否确实不同.

This should not happen, also 1 second difference between NSDate instances is enough. Add an NSLog() with both dates there to see whether they are different indeed.

这篇关于iOS - 如何比较两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆