比较两个 NSDate [英] Compare Between 2 NSDate

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

问题描述

我有 2 个 NSDate 对象,第一个设置为提前一个月,第二个设置为今天.我想检查今天是否在(更大)然后是前一个月的对象之后.

i Have 2 NSDate object the first is set to one month ahead and the seconed is set for today. i want to check if today is after (Bigger) then the month ahead object.

我该怎么做?

推荐答案

阅读 日期和时间编程指南 大量的日期和时间这里详细解释了时间概念(以及 Cocoa 如何处理它们),非常值得一读.

Read the Date and Time Programming Guide a lot of Date & Time concepts (and how Cocoa handle them) are explained here in details, it is really worth reading.

此外,在 NSDate 类参考,您可以找到一个专门的部分比较日期",介绍用于比较两个日期的所有方法.所以你应该使用 laterDate:earlierDate: 方法来完全回答你的问题.您还可以使用 timeIntervalSinceDate: 方法并检查返回的时间间隔的符号(再次参见有关此的文档)

Also, in the NSDate class Reference, you can find a dedicated section "Comparing dates" for all the methods used to compare two dates. So you should use laterDate: or earlierDate: methods that totally answer your question. You can also use the timeIntervalSinceDate: method and check the sign of the returned time interval (see once again the documentation on this)

一般来说,不要犹豫阅读文档,因为所有内容都已经在那里详细解释了,您可以通过这些链接看到

In general, don't hesitate to read the documentation as everything is already explained in there in detail as you can see given those links

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

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