Instance Method

compare(_:)

Indicates the temporal ordering of the receiver and another given date.

Declaration

func compare(_ other: Date) -> ComparisonResult

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 macOS.

Return Value

If:

Discussion

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

See Also

Comparing Dates

func isEqual(to: Date) -> Bool

Returns a Boolean value that indicates whether a given object is a date that is exactly equal the receiver.

func earlierDate(Date) -> Date

Returns the earlier of the receiver and another given date.

func laterDate(Date) -> Date

Returns the later of the receiver and another given date.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software