dateInterval(of:for:)

Returns the starting time and duration of a given calendar component that contains a given date.

iOS
10.0+
macOS
10.12+
tvOS
10.0+
watchOS
3.0+
func dateInterval(of component: Calendar.Component, for date: Date) -> DateInterval?

Parameters

component

A calendar component.

date

The specified date.

Returns

A new DateInterval if the starting time and duration of a component could be calculated, otherwise nil.