如何比较iPhone SDK中的日期? [英] how to compare dates in iphone sdk?

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

问题描述

我有两个日期要比较哪个日期更大?我如何在Objective-C中做到这一点?

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

推荐答案

来自NSDate类参考:

From NSDate class reference:

NSDate -compare :返回NSComparisonResult 指示时间的值 接收器和另一个的订购 给定日期.

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

  • (NSComparisonResult)比较:(NSDate *)另一个日期

参数anotherDate日期与 比较接收者.

Parameters anotherDate The date with which to compare the receiver.

该值不能为零.如果 值是零,行为是 不确定,将来可能会改变 版本的Mac OS X.

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.

如果返回值,则:

接收者和另一个日期是 彼此完全相等, NSOrderedSame

The receiver and anotherDate are exactly equal to each other, NSOrderedSame

接收器的时间晚于 anotherDate,NSOrderedDescending

The receiver is later in time than anotherDate, NSOrderedDescending

接收器的时间早于 anotherDate,NSOrderedAscending.

The receiver is earlier in time than anotherDate, NSOrderedAscending.

讨论此方法检测 日期之间的亚秒级差异. 如果您想将日期与 细度少,使用 timeIntervalSinceDate:比较 两个日期.

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.

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

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