Instance Method
dateInterval(of:for:)
iOS 10.0+
iPadOS 10.0+
Mac Catalyst 10.0+
macOS 10.12+
tvOS 10.0+
watchOS 3.0+
Returns the starting time and duration of a given calendar component that contains a given date.
func dateInterval(of component: Calendar.Component, for date: Date) -> DateInterval?
Parameters
componentA calendar component.
dateThe specified date.
Return Value
A new DateInterval if the starting time and duration of a component could be calculated, otherwise nil.