Important: The information in this document is obsolete and should not be used for new development.
Inherits from | |
Implements | |
Package | com.apple.cocoa.foundation |
Companion guide |
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.
abbreviation
abbreviationForDate
name
secondsFromGMT
secondsFromGMTForDate
isDaylightSavingTime
isDaylightSavingTimeForDate
data
public NSTimeZone
()
This constructor has been deprecated. Use any of the timeZone...
static methods instead.
public NSTimeZone
(int seconds)
This constructor has been deprecated. Use timeZoneForSecondsFromGMT
instead.
public NSTimeZone
(String aTimeZoneName, NSData data)
This constructor has been deprecated. Use timeZoneWithNameAndData
instead.
public NSTimeZone
(String aTimeZoneName, boolean isAbbrev)
This constructor has been deprecated. Use timeZoneWithName
instead.
Returns a dictionary holding the mappings of time zone abbreviations to time zone names.
public static NSDictionary abbreviationDictionary
()
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.
Returns the default time zone set for your application.
public static NSTimeZone defaultTimeZone
()
If no default time zone has been set, this method invokes systemTimeZone
and returns the system time zone.
Returns an array of strings listing the names of all the time zones known to the system.
public static NSArray knownTimeZoneNames
()
Returns an object that forwards all messages to the default time zone for your application.
public static NSTimeZone localTimeZone
()
This behavior is particularly useful for NSGregorianDate objects that are archived or sent as distributed objects and may be interpreted in different locales.
Clears the previously determined system time zone, if any.
public static void resetSystemTimeZone
()
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.
Sets the default time zone for your application to aTimeZone.
public static void setDefaultTimeZone
(NSTimeZone aTimeZone)
There can be only one default time zone, so by setting a new default time zone, you lose the previous one.
Returns the time zone currently used by the system.
public static NSTimeZone systemTimeZone
()
If it can’t figure out the current time zone, returns the GMT time zone.
Returns a time zone object offset from Greenwich Mean Time by seconds.
public static Object timeZoneForSecondsFromGMT
(int seconds)
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.
Returns the time zone object identified by the name aTimeZoneName.
public static Object timeZoneWithName
(String aTimeZoneName, boolean flag)
It searches the time zone information directory for matching names. Returns null
if there is no match for the name.
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)
You should not call this method directly—use timeZoneWithName
to get the time zone object for a given name.
Returns the abbreviation for the receiver, such as “EDT” (Eastern Daylight Time).
public String abbreviation
()
Invokes abbreviationForDate
with the current date as the argument.
Returns the abbreviation for the receiver at the specified date.
public String abbreviationForDate
(NSDate aDate)
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.”
Returns the data that stores the information used by the receiver.
public NSData data
()
This data should be treated as an opaque object.
Returns true
if anObject is an instance of NSTimeZone and satisfies isEqualToTimeZone
.
public boolean equals
(Object anObject)
Returns false
otherwise.
Returns an integer that can be used as a table address in a hash table structure.
public int hashCode
()
Returns true
if the receiver is currently using daylight savings time.
public boolean isDaylightSavingTime
()
This method invokes isDaylightSavingTimeForDate
with the current date as the argument.
Returns true
if the receiver uses daylight savings time at aDate.
public boolean isDaylightSavingTimeForDate
(NSDate aDate)
Returns true
if aTimeZone and the receiver have the same name and data.
public boolean isEqualToTimeZone
(NSTimeZone aTimeZone)
Returns the geopolitical region name that identifies the receiver.
public String name
()
Returns the current difference in seconds between the receiver and Greenwich Mean Time.
public int secondsFromGMT
()
Returns the difference in seconds between the receiver and Greenwich Mean Time at aDate.
public int secondsFromGMTForDate
(NSDate aDate)
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.
public String toString
()
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.
© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)