how to compare dates in iphone sdk?

时光怂恿深爱的人放手 提交于 2019-12-24 07:05:35

问题


i have two dates i want to compare which one is greater date how do i do this in objective-c?


回答1:


From NSDate class reference:

NSDate -compare: Returns an NSComparisonResult value that indicates the temporal ordering of the receiver and another given date.

  • (NSComparisonResult)compare:(NSDate *)anotherDate

Parameters anotherDate The date with which to compare the receiver.

This value must not be nil. If the value is nil, the behavior is undefined and may change in future versions of Mac OS X.

Return Value If:

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.

Discussion This method detects sub-second differences between dates. If you want to compare dates with a less fine granularity, use timeIntervalSinceDate: to compare the two dates.



来源:https://stackoverflow.com/questions/1693316/how-to-compare-dates-in-iphone-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!