Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSTimeZone

Inherits from
Implements
Package
com.apple.cocoa.foundation
Companion guide

Overview

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 for Pacific Standard Time).

NSTimeZone provides several static methods to get time zone objects: timeZoneWithName, timeZoneWithNameAndData, and 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 static method, and with the localTimeZone static 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 NSGregorianDate 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 NSGregorianDate are bound to the default time zone for the current locale.

Tasks

Constructors

Getting Time Zones

Getting the Default Time Zone

Getting Time Zone Information

Getting Information About a Specific Time Zone

Comparing Time Zones

Describing a Time Zone

Constructors

NSTimeZone

public NSTimeZone()

Discussion

This constructor has been deprecated. Use any of the timeZone... static methods instead.

public NSTimeZone(int seconds)

Discussion

This constructor has been deprecated. Use timeZoneForSecondsFromGMT instead.

public NSTimeZone(String aTimeZoneName, NSData data)

Discussion

This constructor has been deprecated. Use timeZoneWithNameAndData instead.

public NSTimeZone(String aTimeZoneName, boolean isAbbrev)

Discussion

This constructor has been deprecated. Use timeZoneWithName instead.

Static Methods

abbreviationDictionary

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

public static NSDictionary abbreviationDictionary()

Discussion

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

Returns the default time zone set for your application.

public static NSTimeZone defaultTimeZone()

Discussion

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

See Also

knownTimeZoneNames

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

public static NSArray knownTimeZoneNames()

localTimeZone

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

public static NSTimeZone localTimeZone()

Discussion

This behavior is particularly useful for NSGregorianDate objects that are archived or sent as distributed objects and may be interpreted in different locales.

See Also

resetSystemTimeZone

Clears the previously determined system time zone, if any.

public static void resetSystemTimeZone()

Discussion

This method also resets the default time zone if it is the same as the system time zone. Subsequent calls to systemTimeZone will attempt to redetermine the system time zone.

setDefaultTimeZone

Sets the default time zone for your application to aTimeZone.

public static void setDefaultTimeZone(NSTimeZone aTimeZone)

Discussion

There can be only one default time zone, so by setting a new default time zone, you lose the previous one.

See Also

systemTimeZone

Returns the time zone currently used by the system.

public static NSTimeZone systemTimeZone()

Discussion

If it can’t figure out the current time zone, returns the GMT time zone.

timeZoneForSecondsFromGMT

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

public static Object timeZoneForSecondsFromGMT(int seconds)

Discussion

The name of the new time zone is GMT +/– the offset, in hours and minutes. Time zones created with this method never have daylight savings, and the offset is constant no matter the date.

See Also

timeZoneWithName

Returns the time zone object identified by the name aTimeZoneName.

public static Object timeZoneWithName(String aTimeZoneName, boolean flag)

Discussion

It searches the time zone information directory for matching names. Returns null if there is no match for the name.

See Also

timeZoneWithNameAndData

Returns the time zone with the name aTimeZoneName whose data has been initialized using the contents of data.

public static Object timeZoneWithNameAndData(String aTimeZoneName, NSData data)

Discussion

You should not call this method directly—use timeZoneWithName to get the time zone object for a given name.

See Also

Instance Methods

abbreviation

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

public String abbreviation()

Discussion

Invokes abbreviationForDate with the current date as the argument.

abbreviationForDate

Returns the abbreviation for the receiver at the specified date.

public String abbreviationForDate(NSDate aDate)

Discussion

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

Returns the data that stores the information used by the receiver.

public NSData data()

Discussion

This data should be treated as an opaque object.

equals

Returns true if anObject is an instance of NSTimeZone and satisfies isEqualToTimeZone.

public boolean equals(Object anObject)

Discussion

Returns false otherwise.

hashCode

Returns an integer that can be used as a table address in a hash table structure.

public int hashCode()

isDaylightSavingTime

Returns true if the receiver is currently using daylight savings time.

public boolean isDaylightSavingTime()

Discussion

This method invokes isDaylightSavingTimeForDate with the current date as the argument.

isDaylightSavingTimeForDate

Returns true if the receiver uses daylight savings time at aDate.

public boolean isDaylightSavingTimeForDate(NSDate aDate)

isEqualToTimeZone

Returns true if aTimeZone and the receiver have the same name and data.

public boolean isEqualToTimeZone(NSTimeZone aTimeZone)

name

Returns the geopolitical region name that identifies the receiver.

public String name()

secondsFromGMT

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

public int secondsFromGMT()

secondsFromGMTForDate

Returns the difference in seconds between the receiver and Greenwich Mean Time at aDate.

public int secondsFromGMTForDate(NSDate aDate)

Discussion

This difference 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.

toString

public String toString()

Discussion

Returns a string description of the receiver, including the name, abbreviation, offset from GMT, and whether or not daylight savings time is currently in effect.



Next Page > Hide TOC


© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.