Instance Method

date(_:matchesComponents:)

Determines if the date has all of the specified date components.

Declaration

func date(_ date: Date, matchesComponents components: DateComponents) -> Bool

Return Value

true if the date matches all of the components, otherwise false.

Discussion

It may be useful to test the return value of nextDate(after:matching:matchingPolicy:behavior:direction:) to find out if the components were obeyed or if the method had to fudge the result value due to missing time (for example, a daylight saving time transition).

See Also

Extracting Components

func component(Calendar.Component, from: Date) -> Int

Returns the value for one component of a date.

func dateComponents(Set<Calendar.Component>, from: Date) -> DateComponents

Returns all the date components of a date, using the calendar time zone.

func dateComponents(in: TimeZone, from: Date) -> DateComponents

Returns all the date components of a date, as if in a given time zone (instead of the Calendar time zone).

enum Calendar.Component

An enumeration for the various components of a calendar 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