Date.FormatStyle.Symbol.TimeZone
A type that specifies a format for the time zone in a date format style.
Declaration
struct TimeZoneOverview
The type Date.FormatStyle.Symbol.TimeZone includes static factory variables and methods that create custom Date.FormatStyle.Symbol.TimeZone objects:
Factory variable | Description |
|---|---|
The specific, non-location representation of a timezone. For example, | |
The generic, non-location representation of a timezone. For example, | |
The ISO 8601 representation of the timezone with hours, minutes, and optional seconds. For example, | |
The localized GMT format representation of a timezone. For example, | |
The timezone identifier. For example, | |
The exemplar city for a timezone. For example, | |
The generic location representation of a timezone. For example, |
To customize the hour format in a string representation of a Date, use timeZone(_:). The following example shows a variety of Date.FormatStyle.Symbol.TimeZone format styles applied to a date.
let meetingDate = Date() // Feb 9, 2021 at 7:00 PM
meetingDate.formatted(Date.FormatStyle().timeZone(.specificName(.short)))
// CDT
meetingDate.formatted(Date.FormatStyle().timeZone(.specificName(.long)))
// Central Daylight Time
meetingDate.formatted(Date.FormatStyle().timeZone(.genericName(.short)))
// CT
meetingDate.formatted(Date.FormatStyle().timeZone(.genericName(.long)))
// Central Time
meetingDate.formatted(Date.FormatStyle().timeZone(.iso8601(.short)))
// -0500
meetingDate.formatted(Date.FormatStyle().timeZone(.iso8601(.long)))
// -05:00
meetingDate.formatted(Date.FormatStyle().timeZone(.localizedGMT(.short)))
// GMT-5
meetingDate.formatted(Date.FormatStyle().timeZone(.localizedGMT(.long)))
// GMT-05:00
meetingDate.formatted(Date.FormatStyle().timeZone(.identifier(.short)))
// uschi
meetingDate.formatted(Date.FormatStyle().timeZone(.identifier(.long)))
// America/Chicago
meetingDate.formatted(Date.FormatStyle().timeZone(.exemplarLocation))
// Chicago
meetingDate.formatted(Date.FormatStyle().timeZone(.genericLocation))
// Chicago Time
If you don’t provide a format, the system formats a timezone using the short specificName(_:) static function with the width Date.FormatStyle.Symbol.TimeZone.Width.short.
For more information about formatting dates, see the Date.FormatStyle.
Topics
Modifying a Time Zone
specificName(_:)genericName(_:)iso8601(_:)localizedGMT(_:)identifier(_:)exemplarLocationgenericLocation
Comparing Time Zones
Supporting Enumerations
Type Properties
See Also
Modifying Date Style Format Symbols
Date.FormatStyle.Symbol.CyclicYearDate.FormatStyle.Symbol.DayDate.FormatStyle.Symbol.DayOfYearDate.FormatStyle.Symbol.DayPeriodDate.FormatStyle.Symbol.EraDate.FormatStyle.Symbol.HourDate.FormatStyle.Symbol.MinuteDate.FormatStyle.Symbol.MonthDate.FormatStyle.Symbol.QuarterDate.FormatStyle.Symbol.SecondDate.FormatStyle.Symbol.SecondFractionDate.FormatStyle.Symbol.StandaloneMonthDate.FormatStyle.Symbol.StandaloneQuarterDate.FormatStyle.Symbol.StandaloneWeekdayDate.FormatStyle.Symbol.VerbatimHour