Class

NSTimeZone

Information about standard time conventions associated with a specific geopolitical region.

Declaration

@interface NSTimeZone : NSObject

Overview

Time zones represent the standard time policies for a geopolitical region. Time zones have identifiers like “America/Los_Angeles” and can also be identified by abbreviations, such as PST for Pacific Standard Time. You can create time zone objects by ID with initWithName: and by abbreviation with timeZoneWithAbbreviation:.

Time zones can also represent a temporal offset—either plus or minus—from Greenwich Mean Time (GMT). For example, the temporal offset of Pacific Standard Time is 8 hours behind Greenwich Mean Time (GMT-8). You can create time zone objects with a temporal offset by using timeZoneForSecondsFromGMT:.

You typically work with system time zones rather than creating time zones by identifier or by offset. The systemTimeZone class property returns the time zone currently used by the system, if known. This value is cached once the property is accessed and doesn't reflect any system time zone changes until you call the resetSystemTimeZone method. The localTimeZone class property returns an autoupdating proxy object that always returns the current time zone used by the system. You can also set the defaultTimeZone class property to make your app run as if it were in a different time zone than the system.

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

Topics

Working with System Time Zones

localTimeZone

An object that tracks the current system time zone.

systemTimeZone

The time zone currently used by the system.

+ resetSystemTimeZone

Clears any time zone value cached for the systemTimeZone property.

defaultTimeZone

The default time zone for the current app.

Creating Time Zones

+ timeZoneWithName:

Returns the time zone object identified by a given identifier.

+ timeZoneWithName:data:

Returns the time zone with a given identifier whose data has been initialized using given data.

- initWithName:

Returns a time zone initialized with a given identifier.

- initWithName:data:

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

+ timeZoneWithAbbreviation:

Returns the time zone object identified by a given abbreviation.

+ timeZoneForSecondsFromGMT:

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

knownTimeZoneNames

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

abbreviationDictionary

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

Getting Time Zone Information

name

The geopolitical region ID that identifies the receiver.

abbreviation

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

- abbreviationForDate:

Returns the abbreviation for the receiver at a given date.

secondsFromGMT

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

- secondsFromGMTForDate:

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

data

The data that stores the information used by the receiver.

timeZoneDataVersion

Returns the time zone data version.

NSTimeZoneNameStyle

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

Working with Daylight Savings

daylightSavingTime

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

- isDaylightSavingTimeForDate:

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

daylightSavingTimeOffset

The current daylight saving time offset of the receiver.

- daylightSavingTimeOffsetForDate:

Returns the daylight saving time offset for a given date.

nextDaylightSavingTimeTransition

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

- nextDaylightSavingTimeTransitionAfterDate:

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

Comparing Time Zones

- isEqualToTimeZone:

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

Describing Time Zones

- localizedName:locale:

Returns the localized name of the time zone.

description

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

NSSystemTimeZoneDidChangeNotification

A notification posted when the time zone changes.

Relationships

Inherits From

See Also

Calendrical Calculations

NSDateComponents

An object that specifies a date or time in terms of units (such as year, month, day, hour, and minute) to be evaluated in a calendar system and time zone.

NSCalendar

An object that defines the relationships between calendar units (such as eras, years, and weekdays) and absolute points in time, providing features for calculation and comparison of dates.

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