One Logo Pool Ball
Foundation · IOS API REFERENCE

TimeZone

struct · iOS 8.0+ · SDK 27.1

struct TimeZone

Information about standard time conventions associated with a specific geopolitical region. `TimeZone` defines the behavior of a time zone. Time zone values represent geopolitical regions. Consequently, these values have names for these regions. Time zone values also represent a temporal offset, either plus or minus, from Greenwich Mean Time (GMT) and an abbreviation (such as PST for Pacific Standard Time). `TimeZone` provides two static functions to get time zone values: `current` and `autoupdatingCurrent`. The `autoupdatingCurrent` time zone automatically tracks updates made by the user. Note that time zone database entries such as "America/Los_Angeles" are IDs, not names. An example of a time zone name is "Pacific Daylight Time". Although many `TimeZone` functions include the word "name", they refer to IDs. Cocoa does not provide any API to change the time zone of the computer, or of other applications.

Members (21)

method · iOS 8.0+

daylightSavingTimeOffset

TypeScript
daylightSavingTimeOffset(date?: globalThis.Date): number
Swift declaration
func daylightSavingTimeOffset(for date: Date = Date()) -> TimeInterval

Returns the daylight saving time offset for a given date. - parameter date: The date to use for the calculation. The default value is the current date.

method · iOS 8.0+

isDaylightSavingTime

TypeScript
isDaylightSavingTime(date?: globalThis.Date): boolean
Swift declaration
func isDaylightSavingTime(for date: Date = Date()) -> Bool

Returns a Boolean value that indicates whether the receiver uses daylight saving time at a given date. - parameter date: The date to use for the calculation. The default value is the current date.

method · iOS 8.0+

nextDaylightSavingTimeTransition

TypeScript
nextDaylightSavingTimeTransitionAfter(date: globalThis.Date): (globalThis.Date) | null
Swift declaration
func nextDaylightSavingTimeTransition(after date: Date) -> Date?

Returns the next daylight saving time transition after a given date. - parameter date: A date. - returns: The next daylight saving time transition after `date`. Depending on the time zone, this function may return a change of the time zone's offset from GMT. Returns `nil` if the time zone of the receiver does not observe daylight savings time as of `date`.

get · iOS 8.0+

nextDaylightSavingTimeTransition

TypeScript
get nextDaylightSavingTimeTransition(): (globalThis.Date) | null
Swift declaration
var nextDaylightSavingTimeTransition: Date? { get }

The date of the next (after the current instant) daylight saving time transition for the time zone. Depending on the time zone, the value of this property may represent a change of the time zone's offset from GMT. The value is `nil` if the time zone does not currently observe daylight saving time.

get · iOS 8.0+

timeZoneDataVersion

TypeScript
static get timeZoneDataVersion(): string
Swift declaration
static var timeZoneDataVersion: String { get }

Returns the time zone data version.

get · iOS 8.0+

knownTimeZoneIdentifiers

TypeScript
static get knownTimeZoneIdentifiers(): Array<string>
Swift declaration
static var knownTimeZoneIdentifiers: [String] { get }

Returns an array of strings listing the identifier of all the time zones known to the system.

init · iOS 8.0+

init

TypeScript
static initIdentifier(identifier: string): (TimeZone) | null
Swift declaration
init?(identifier: String)

Returns a time zone initialized with a given identifier. An example identifier is "America/Los_Angeles". If `identifier` is an unknown identifier, then returns `nil`.

get · iOS 8.0+

identifier

TypeScript
get identifier(): string
Swift declaration
var identifier: String { get }

The geopolitical region identifier that identifies the time zone.

get · iOS 8.0+

description

TypeScript
get description(): string
Swift declaration
var description: String { get }

A textual representation of this instance. Calling this property directly is discouraged. Instead, convert an instance of any type to a string by using the `String(describing:)` initializer. This initializer works with any type, and uses the custom `description` property for types that conform to `CustomStringConvertible`: struct Point: CustomStringConvertible { let x: Int, y: Int var description: String { return "(\(x), \(y))" } } let p = Point(x: 21, y: 30) let s = String(describing: p) print(s) // Prints "(21, 30)" The conversion of `p` to a string in the assignment to `s` uses the `Point` type's `description` property.

method · iOS 8.0+

abbreviation

TypeScript
abbreviation(date?: globalThis.Date): (string) | null
Swift declaration
func abbreviation(for date: Date = Date()) -> String?

Returns the abbreviation for the time zone at a given date. Note that the abbreviation may be different at different dates. For example, during daylight saving time the US/Eastern time zone has an abbreviation of "EDT." At other times, its abbreviation is "EST." - parameter date: The date to use for the calculation. The default value is the current date.

init · iOS 8.0+

init

TypeScript
static initAbbreviation(abbreviation: string): (TimeZone) | null
Swift declaration
init?(abbreviation: String)

Returns a time zone identified by a given abbreviation. In general, you are discouraged from using abbreviations except for unique instances such as "GMT". Time Zone abbreviations are not standardized and so a given abbreviation may have multiple meanings--for example, "EST" refers to Eastern Time in both the United States and Australia - parameter abbreviation: The abbreviation for the time zone. - returns: A time zone identified by abbreviation determined by resolving the abbreviation to an identifier using the abbreviation dictionary and then returning the time zone for that identifier. Returns `nil` if there is no match for abbreviation.

get · iOS 8.0+

customMirror

TypeScript
get customMirror(): SDKHandle
Swift declaration
var customMirror: Mirror { get }

The custom mirror for this instance. If this type has value semantics, the mirror should be unaffected by subsequent mutations of the instance.

method · iOS 8.0+

localizedName

TypeScript
localizedName(style: NSTimeZone_NameStyle, locale?: (Locale) | null): (string) | null
Swift declaration
func localizedName(for style: TimeZone.NameStyle, locale: Locale?) -> String?

Returns the name of the receiver localized for a given locale.

method · iOS 8.0+

secondsFromGMT

TypeScript
secondsFromGMT(date?: globalThis.Date): number
Swift declaration
func secondsFromGMT(for date: Date = Date()) -> Int

The current difference in seconds between the time zone and Greenwich Mean Time. - parameter date: The date to use for the calculation. The default value is the current date.

init · iOS 8.0+

init

TypeScript
static initSecondsFromGMT(seconds: number): (TimeZone) | null
Swift declaration
init?(secondsFromGMT seconds: Int)

Returns a time zone initialized with a specific number of seconds from GMT. Time zones created with this never have daylight savings and the offset is constant no matter the date. The identifier and abbreviation do NOT follow the POSIX convention (of minutes-west). - parameter seconds: The number of seconds from GMT. - returns: A time zone, or `nil` if a valid time zone could not be created from `seconds`.

get · iOS 8.0+

debugDescription

TypeScript
get debugDescription(): string
Swift declaration
var debugDescription: String { get }

A textual representation of this instance, suitable for debugging. Calling this property directly is discouraged. Instead, convert an instance of any type to a string by using the `String(reflecting:)` initializer. This initializer works with any type, and uses the custom `debugDescription` property for types that conform to `CustomDebugStringConvertible`: struct Point: CustomDebugStringConvertible { let x: Int, y: Int var debugDescription: String { return "(\(x), \(y))" } } let p = Point(x: 21, y: 30) let s = String(reflecting: p) print(s) // Prints "(21, 30)" The conversion of `p` to a string in the assignment to `s` uses the `Point` type's `debugDescription` property.

get · iOS 8.0+

autoupdatingCurrent

TypeScript
static get autoupdatingCurrent(): TimeZone
Swift declaration
static var autoupdatingCurrent: TimeZone { get }

The time zone currently used by the system, automatically updating to the user's current preference. If this time zone is mutated, then it no longer tracks the system time zone. The autoupdating time zone only compares equal to itself.

get · iOS 8.0+

abbreviationDictionary

TypeScript
static get abbreviationDictionary(): Record<string, string>
Swift declaration
static var abbreviationDictionary: [String : String] { get set }

Returns the mapping of abbreviations to time zone identifiers.

set · iOS 8.0+

abbreviationDictionary

TypeScript
static set abbreviationDictionary(value: Record<string, string>)
Swift declaration
static var abbreviationDictionary: [String : String] { get set }

Returns the mapping of abbreviations to time zone identifiers.

get · iOS 16.0+

gmt

TypeScript
static get gmt(): TimeZone
Swift declaration
static var gmt: TimeZone { get }
get · iOS 8.0+

current

TypeScript
static get current(): TimeZone
Swift declaration
static var current: TimeZone { get }

The time zone currently used by the system.

Skipped declarations

No declarations were skipped in this snapshot.

All Foundation types →