Structure
Date.FormatStyle.Symbol.TimeZone
struct TimeZone
Overview
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
Type Properties
static var exemplarLocation: Date.FormatStyle.Symbol.TimeZoneThe exemplar city (location) for the time zone. The localized exemplar city name for the special zone or unknown is used as the fallback if it is unavailable. For example, “Los Angeles”.static var genericLocation: Date.FormatStyle.Symbol.TimeZoneThe generic location format. Falls back tolongLocalizedGMTif unavailable. Recommends for presenting possible time zone choices for user selection. For example, “Los Angeles Time”.static let omitted: Date.FormatStyle.Symbol.TimeZoneThe option for not including the symbol in the formatted output.
Type Methods
static func genericName(Date.FormatStyle.Symbol.TimeZone.Width) -> Date.FormatStyle.Symbol.TimeZoneGeneric non-location format. Falls back togenericLocationif unavailable. For example, short: “PT”. Fallback again tolocalizedGMT(.short)ifgenericLocation(.short)is unavailable. long: “Pacific Time”static func identifier(Date.FormatStyle.Symbol.TimeZone.Width) -> Date.FormatStyle.Symbol.TimeZoneThe time zone ID. For example, short: “uslax” long: “America/Los_Angeles”.static func iso8601(Date.FormatStyle.Symbol.TimeZone.Width) -> Date.FormatStyle.Symbol.TimeZoneThe ISO8601 format with hours, minutes and optional seconds fields. For example, short: “-0800” long: “-08:00” or “-07:52:58”.static func localizedGMT(Date.FormatStyle.Symbol.TimeZone.Width) -> Date.FormatStyle.Symbol.TimeZoneShort localized GMT format. For example, short: “GMT-8” long: “GMT-8:00”static func specificName(Date.FormatStyle.Symbol.TimeZone.Width) -> Date.FormatStyle.Symbol.TimeZoneSpecific non-location format. Falls back toshortLocalizedGMTif unavailable. For example, short: “PDT” long: “Pacific Daylight Time”.
Enumerations
enum WidthA type representing the width of a time zone in a format style.
Relationships
Conforms To
Swift.EquatableSwift.HashableSwift.SendableSwift.SendableMetatype