Instance Method


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


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



The time zone to use when returning the components. This value overrides the time zone of the receiving NSCalendar.


The date for which to perform the calculation.

Return Value

An NSDateComponents object containing all the components from the given date, calculated using the given time zone.


If you want "date information in a given time zone" for the purpose to displaying it, you should use DateFormatter to format the date.

See Also

Extracting Components

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

Returns whether a given date matches all of the given date 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.

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