更新时间:2022-05-04 22:30:17
返回一个NSComparisonResult值,指示接收者的时间顺序和另一个给定日期。
Returns an NSComparisonResult value that indicates the temporal ordering of the receiver and another given date.
- (NSComparisonResult)compare:(NSDate *)anotherDate
参数 anotherD吃了
比较
接收者的日期。该值不得为零。
如果值为nil,则行为为
undefined,并且可能在将来的
版本的Mac OS X中发生变化。
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.
返回值
如果:
接收者和anotherDate完全相等
相互之间,
NSOrderedSame
The receiver and anotherDate are
exactly equal to each other,
NSOrderedSame
接收者稍后是
时间比anotherDate,
NSOrderedDescending
The receiver is later in
time than anotherDate,
NSOrderedDescending
收件人是
早于其他日期,
NSOrderedAscending
The receiver is
earlier in time than anotherDate,
NSOrderedAscending
换句话说:
if ([date1 compare:date2] == NSOrderedSame) ...
请注意,在您的特定情况下,读取和写入此内容可能更容易:
Note that it might be easier in your particular case to read and write this :
if ([date2 isEqualToDate:date2]) ...
参见关于这个的Apple文档。