如何比较两个日期在iphone? [英] How to compare two dates in iphone?

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

问题描述

我想比较今天的日期和来自我的资料库的其他日期。
例如,2011-03-25与2011-02-25比较



如何能形成我的数据库日期,因为NSDateFormatter需要NSDdate数据类型? / p>

解决方案

Cocoa对此有几种方法:



在NSDate中



- isEqualToDate:

- earlierDate:

- laterDate:

- compare:



当你使用 - (NSComparisonResult)compare:(NSDate *)anotherDate时,你会得到以下结果之一:



接收者和anotherDate彼此完全相等NSOrderedSame
接收者在时间上比另一个日期晚NSOrderedDescending
接收者在时间上早于anotherDate,NSOrderedAscending。

更多阅读



只要浏览博文,就会有许多与日期相关的效用函数。



http://arstechnica.com/apple/guides/2010/03/how-to-real-world-dates-with-the-iphone-sdk.ars/2 < a>


I want to compare the todays date and other date coming from my database. For example, 2011-03-25 compare it with 2011-02-25

How can i formate my database date as the NSDateFormatter require NSDdate datatype ?

解决方案

Cocoa has couple of methods for this:

in NSDate

– isEqualToDate:
– earlierDate:
– laterDate:
– compare:

When you use - (NSComparisonResult)compare:(NSDate *)anotherDate ,you get back one of these:

The receiver and anotherDate are exactly equal to each other, NSOrderedSame
The receiver is later in time than anotherDate, NSOrderedDescending
The receiver is earlier in time than anotherDate, NSOrderedAscending.

for more read the SO post

Just go through the blog post, there are many date related utility functions.

http://arstechnica.com/apple/guides/2010/03/how-to-real-world-dates-with-the-iphone-sdk.ars/2

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

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