Skip to content

Instance Method

dateComponents(in:from:)

iOS 8.0+ iPadOS 8.0+ Mac Catalyst 8.0+ macOS 10.10+ tvOS 9.0+ watchOS 2.0+
Returns all the date components of a date, as if in a given time zone (instead of the Calendar time zone).
func dateComponents(in timeZone: TimeZone, from date: Date) -> DateComponents

Parameters

timeZone

The TimeZone to use.

date

The Date to use.

Return Value

All components, calculated using the Calendar and TimeZone.

Discussion

The time zone overrides the time zone of the Calendar for the purposes of this calculation.

Note

If you want “date information in a given time zone” in order to display it, you should use DateFormatter to format the date.