PATH  Documentation > Mac OS X > Foundation Reference: Objective-C



Table of Contents

NSTimeZone


Inherits from:
NSObject
Conforms to:
NSCoding
NSCopying
NSObject (NSObject)
Declared in:
Foundation/NSTimeZone.h




Class Description


NSTimeZone is an abstract class that defines the behavior of time zone objects. 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").

NSTimeZone provides several class methods to get time zone objects: timeZoneWithName:, timeZoneWithAbbreviation:, timeZoneForSecondsFromGMT: . The class also permits you to set the default time zone within your application ( setDefaultTimeZone:). You can access this default time zone at any time with the defaultTimeZone class method, and with the localTimeZone 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.

Some NSCalendarDate methods return date objects that are automatically bound to time zone objects. These date objects use the functionality of NSTimeZone to adjust dates for the proper locale. Unless you specify otherwise, objects returned from NSCalendarDate are bound to the default time zone for the current locale.




Adopted Protocols


NSCoding
- encodeWithCoder:
- initWithCoder:
NSCopying
- copyWithZone:


Method Types


Getting time zones
+ timeZoneWithAbbreviation:
+ timeZoneWithName:
+ timeZoneWithName:data:
+ timeZoneForSecondsFromGMT:
- initWithName:
- initWithName:data:
Getting the default time zone
+ localTimeZone
+ defaultTimeZone
+ setDefaultTimeZone:
+ resetSystemTimeZone
Getting time zone information
+ abbreviationDictionary
+ knownTimeZoneNames
Getting information about a specific time zone
- abbreviation
- abbreviationForDate:
- name
- secondsFromGMT
- secondsFromGMTForDate:
- isDaylightSavingTime
- isDaylightSavingTimeForDate:
- data
Comparing time zones
- isEqualToTimeZone:
Describing a time zone
- description


Class Methods



abbreviationDictionary

+ (NSDictionary *)abbreviationDictionary

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

More than one time zone may have the same abbreviation. For example, US/Pacific and Canada/Pacific both use the abbreviation "PST." In these cases abbreviationDictionary chooses a single name to map the abbreviation to.



defaultTimeZone

+ (NSTimeZone *)defaultTimeZone

Returns the default time zone set for your application. If no default time zone has been set, this method invokes systemTimeZone and returns the system time zone.

See Also: + localTimeZone, + setDefaultTimeZone:, + systemTimeZone



knownTimeZoneNames

+ (NSArray *)knownTimeZoneNames

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

localTimeZone

+ (NSTimeZone *)localTimeZone

Returns an object that forwards all messages to the default time zone for your application. This behavior is particularly useful for NSCalendarDate objects that are archived or sent as Distributed Objects and may be interpreted in different locales.

See Also: + defaultTimeZone, + setDefaultTimeZone:



resetSystemTimeZone

+ (void)resetSystemTimeZone

Clears the previously determined system time zone, if any. Subsequent calls to systemTimeZone will attempt to redetermine the system time zone.

setDefaultTimeZone:

+ (void)setDefaultTimeZone:(NSTimeZone *)aTimeZone

Sets the time zone appropriate for your application. There can be only one default time zone, so by setting a new default time zone, you lose the previous one.

See Also: + defaultTimeZone, + localTimeZone



systemTimeZone

+ (NSTimeZone *)systemTimeZone

Returns the time zone currently used by the system. If it can't figure out the current time zone, returns the GMT time zone.

timeZoneForSecondsFromGMT:

+ (NSTimeZone *)timeZoneForSecondsFromGMT:(int)seconds

Returns a time zone object with seconds offset from Greenwich Mean Time. The name of the new time zone is GMT +/- the offset, in hours and minutes. Time zones created with this never have daylight savings and the offset is constant no matter the date; the name and abbreviation do NOT follow the POSIX convention of minutes-west.

See Also: + timeZoneWithAbbreviation:, + timeZoneWithName:



timeZoneWithAbbreviation:

+ (NSTimeZone *)timeZoneWithAbbreviation:(NSString *)abbreviation

Returns the time zone object identified by abbreviation by resolving the abbreviation to a name using the abbreviation dictionary, and then returning the time zone for that name. Returns nil if there is no match for abbreviation.

See Also: + abbreviationDictionary, + timeZoneForSecondsFromGMT:, + timeZoneWithName:



timeZoneWithName:

+ (NSTimeZone *)timeZoneWithName:(NSString *)aTimeZoneName

Returns the time zone object identified by the name aTimeZoneName. It searches the time zone information directory for matching names. Returns nil if there is no match on the name.

See Also: + timeZoneForSecondsFromGMT:, + timeZoneWithAbbreviation:, + knownTimeZoneNames



timeZoneWithName:data:

+ (NSTimeZone *)timeZoneWithName:(NSString *)aTimeZoneName data:(NSData *)data

Returns the time zone with the name aTimeZoneName whose data has been initialized using the contents of data. You should not call this method directly-use timeZoneWithName: to get the time zone object for a given name.

See Also: + timeZoneWithName:




Instance Methods



abbreviation

- (NSString *)abbreviation

Returns the abbreviation for the time zone, such as "EDT" (Eastern Daylight Time). Invokes abbreviationForDate: with the current date as the argument.

abbreviationForDate:

- (NSString *)abbreviationForDate:(NSDate *)aDate

Returns the abbreviation for the time zone object at the specified date. Note that the abbreviation may be different at different dates. For example, during Daylight Savings Time the US/Eastern time zone has an abbreviation of "EDT." At other times, its abbreviation is "EST."

data

- (NSData *)data

Returns the data that stores the information used by the time zone. This data should be treated as an opaque object.

description

- (NSString *)description

Returns the description of the time zone, including the name, abbreviation, offset from GMT, and whether or not Daylight Savings Time is currently in effect.

initWithName:

- (id)initWithName:(NSString *)aName

Initializes a time zone with aName. If aName is a known name, this method calls initWithName:data: with the appropriate data object.

initWithName:data:

- (id)initWithName:(NSString *)aName data:(NSData *)data

Initializes a time zone with aName and data. You should not call this method directly-use initWithName: to get a time zone object.

isDaylightSavingTime

- (BOOL)isDaylightSavingTime

Returns YES if the time zone is currently using Daylight Savings Time. This method invokes isDaylightSavingTimeForDate: with the current date as the argument.

isDaylightSavingTimeForDate:

- (BOOL)isDaylightSavingTimeForDate:(NSDate *)aDate

Returns YES if the time zone uses Daylight Savings Time at aDate.

isEqualToTimeZone:

- (BOOL)isEqualToTimeZone:(NSTimeZone *)aTimeZone

Returns YES if aTimeZone and the receiving time zone have the same name and data.

name

- (NSString *)name

Returns the geopolitical region name that identifies the time zone.

secondsFromGMT

- (int)secondsFromGMT

Returns the current difference in seconds between the time zone and Greenwich Mean Time.

secondsFromGMTForDate:

- (int)secondsFromGMTForDate:(NSDate *)aDate

Returns the difference in seconds between the time zone and Greenwich Mean Time at aDate. This may be different from the current difference if the time zone changes its offset from GMT at different points in the year-for example, the U.S. time zones change with daylight savings time.


Table of Contents