Indicates the temporal ordering of the receiver and another given date.
SDKs
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
- (NSComparison Result)compare:(NSDate *)other;
Parameters
anotherDate
The date with which to compare the receiver.
This value must not be
nil
. If the value isnil
, the behavior is undefined and may change in future versions of macOS.
Return Value
If:
The receiver and
another
are exactly equal to each other,Date NSOrdered
Same The receiver is later in time than
another
,Date NSOrdered
Descending The receiver is earlier in time than
another
,Date NSOrdered
.Ascending
Discussion
This method detects sub-second differences between dates. If you want to compare dates with a less fine granularity, use time
to compare the two dates.