Instance Method


Returns whether a given date matches all of the given date components.


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



The date for which to perform the calculation.


The date components to match.

Return Value

true if the given date matches the given components, otherwise false.


This method is useful for determining whether dates calculated by methods like nextDate(after:matching:value:options:) or enumerateDates(startingAfter:matching:options:using:) are exact, or required an adjustment due to a nonexistent time.

See Also

Extracting Components

func component(NSCalendar.Unit, from: Date) -> Int

Returns the specified date component from a given date.

func components(NSCalendar.Unit, from: Date) -> DateComponents

Returns the date components representing a given date.

func components(NSCalendar.Unit, from: Date, to: Date, options: NSCalendar.Options) -> DateComponents

Returns the difference between two supplied dates as date components.

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

Returns all the date components of a date, as if in a given time zone (instead of the receiving calendar’s time zone).

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