An object containing information about local time conventions that bridges to TimeZone; use NSTimeZone when you need reference semantics or other Foundation-specific behavior.


Time zone objects represent geopolitical regions. Consequently, these objects have names for these regions. Time zone objects also represent a temporal offset, either plus or minus, from Greenwich Mean Time (GMT) and an abbreviation (such as PST for Pacific Standard Time).

NSTimeZone provides several class methods to get time zone objects: timeZoneWithName:, timeZoneWithName:data:, init(abbreviation:), and init(forSecondsFromGMT:). The class also permits you to set the default time zone within your application (setDefault(_:)). You can access this default time zone at any time with the default class method, and with the local class method, you can get a relative time zone object that decodes itself to become the default time zone for any locale in which it finds itself.

Note that, strictly, 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 NSTimeZone method names 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.

NSTimeZone is “toll-free bridged” with its Core Foundation counterpart, CFTimeZone. See Toll-Free Bridging for more information on toll-free bridging.


Working with System Time Zones

class var local: TimeZone

Returns an object that forwards all messages to the default time zone for the current application.

class var `default`: TimeZone

Returns the default time zone for the current application.

class var system: TimeZone

Returns the time zone currently used by the system.

class func resetSystemTimeZone()

Resets the system time zone object cached by the application, if any.

Creating and Initializing Time Zones

init?(name: String)

Returns a time zone initialized with a given identifier.

init?(name: String, data: Data?)

Initializes a time zone with a given identifier and time zone data.

init?(abbreviation: String)

Returns the time zone object identified by a given abbreviation.

init(forSecondsFromGMT: Int)

Returns a time zone object offset from Greenwich Mean Time by a given number of seconds.

class var knownTimeZoneNames: [String]

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

class var abbreviationDictionary: [String : String]

Returns a dictionary holding the mappings of time zone abbreviations to time zone names.

Getting Time Zone Information

var name: String

The geopolitical region ID that identifies the receiver.

var abbreviation: String?

The abbreviation for the receiver, such as “EDT” (Eastern Daylight Time).

func abbreviation(for: Date)

Returns the abbreviation for the receiver at a given date.

var secondsFromGMT: Int

The current difference in seconds between the receiver and Greenwich Mean Time.

func secondsFromGMT(for: Date)

Returns the difference in seconds between the receiver and Greenwich Mean Time at a given date.

var data: Data

The data that stores the information used by the receiver.

class var timeZoneDataVersion: String

Returns the time zone data version.

enum NSTimeZone.NameStyle

Constants you use to specify a style when presenting time zone names.

Working with Daylight Savings

var isDaylightSavingTime: Bool

A Boolean value that indicates whether the receiver is currently using daylight saving time.

func isDaylightSavingTime(for: Date)

Indicates whether the receiver uses daylight saving time on a given date.

var daylightSavingTimeOffset: TimeInterval

The current daylight saving time offset of the receiver.

func daylightSavingTimeOffset(for: Date)

Returns the daylight saving time offset for a given date.

var nextDaylightSavingTimeTransition: Date?

The date of the next daylight saving time transition for the receiver.

func nextDaylightSavingTimeTransition(after: Date)

Returns the next daylight saving time transition after a given date.

Comparing Time Zones

func isEqual(to: TimeZone)

Indicates whether the receiver has the same name and data as the specified time zone.

Describing Time Zones

func localizedName(NSTimeZone.NameStyle, locale: Locale?)

Returns the localized name of the time zone.

var description: String

A textual description of the time zone including the name, abbreviation, offset from GMT, and whether or not daylight saving time is currently in effect.

Recognizing Notifications

static let NSSystemTimeZoneDidChange: NSNotification.Name

A notification posted when the time zone changes.


Inherits From

See Also

Using Reference Types

typealias TimeZone.ReferenceType

An alias for this value type's equivalent reference type.