比较两个日期 [英] Compare two dates

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

问题描述

如何比较两个不同的日期,以了解哪个日期较晚?例如,在 date1 中,我将在下载一些数据后存储一个日期,在 date2 中,日期。然后我需要检查哪一个更大/更晚:像 if(date1> date2)

类似:

  NSDate * timeNow = [NSDate date]; 

//如果少于30秒,执行某些操作
if([timeNow timeIntervalSinceDate:anEarlierTime]< 30.0f)
{
//做某事
}


How can I compare two different dates to find out which is the later date? For example, in date1 I will store one date after downloading some data, and in date2, I will store the current date. Then I need to check which one is greater/later: something like if(date1>date2).

解决方案

Something like:

    NSDate* timeNow = [NSDate date];

    // If less than 30 seconds, do something
    if ([timeNow timeIntervalSinceDate:anEarlierTime] < 30.0f)
    {
        // Do something
    }

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

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