Save This Page
Home » apache-harmony-6.0-src-r917296-snapshot » java » util » [javadoc | source]
java.util
abstract public class: TimeZone [javadoc | source]
java.lang.Object
   java.util.TimeZone

All Implemented Interfaces:
    Cloneable, Serializable

Direct Known Subclasses:
    SimpleTimeZone

{@code TimeZone} represents a time zone offset, taking into account daylight savings.

Typically, you get a {@code TimeZone} using {@code getDefault} which creates a {@code TimeZone} based on the time zone where the program is running. For example, for a program running in Japan, {@code getDefault} creates a {@code TimeZone} object based on Japanese Standard Time.

You can also get a {@code TimeZone} using {@code getTimeZone} along with a time zone ID. For instance, the time zone ID for the U.S. Pacific Time zone is "America/Los_Angeles". So, you can get a U.S. Pacific Time {@code TimeZone} object with the following:

TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
You can use the {@code getAvailableIDs} method to iterate through all the supported time zone IDs. You can then choose a supported ID to get a {@code TimeZone}. If the time zone you want is not represented by one of the supported IDs, then you can create a custom time zone ID with the following syntax:
GMT[+|-]hh[[:]mm]
For example, you might specify GMT+14:00 as a custom time zone ID. The {@code TimeZone} that is returned when you specify a custom time zone ID does not include daylight savings time.

For compatibility with JDK 1.1.x, some other three-letter time zone IDs (such as "PST", "CTT", "AST") are also supported. However, their use is deprecated because the same abbreviation is often used for multiple time zones (for example, "CST" could be U.S. "Central Standard Time" and "China Standard Time"), and the Java platform can then only recognize one of them.

Please note the type returned by factory methods, i.e. {@code getDefault()} and {@code getTimeZone(String)}, is implementation dependent, so it may introduce serialization incompatibility issues between different implementations.

Field Summary
public static final  int SHORT    The SHORT display name style. 
public static final  int LONG    The LONG display name style. 
static  TimeZone GMT     
Constructor:
 public TimeZone() 
Method from java.util.TimeZone Summary:
clone,   getAvailableIDs,   getAvailableIDs,   getDSTSavings,   getDefault,   getDisplayName,   getDisplayName,   getDisplayName,   getDisplayName,   getID,   getOffset,   getOffset,   getRawOffset,   getTimeZone,   hasSameRules,   inDaylightTime,   setDefault,   setID,   setRawOffset,   useDaylightTime
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.util.TimeZone Detail:
 public Object clone() 
    Returns a new {@code TimeZone} with the same ID, {@code rawOffset} and daylight savings time rules as this {@code TimeZone}.
 public static synchronized String[] getAvailableIDs() 
    Gets the available time zone IDs. Any one of these IDs can be passed to {@code get()} to create the corresponding {@code TimeZone} instance.
 public static synchronized String[] getAvailableIDs(int offset) 
    Gets the available time zone IDs which match the specified offset from GMT. Any one of these IDs can be passed to {@code get()} to create the corresponding {@code TimeZone} instance.
 public int getDSTSavings() 
    Gets the daylight savings offset in milliseconds for this {@code TimeZone}.

    This implementation returns 3600000 (1 hour), or 0 if the time zone does not observe daylight savings.

    Subclasses may override to return daylight savings values other than 1 hour.

 public static synchronized TimeZone getDefault() 
    Gets the default time zone.
 public final String getDisplayName() 
    Gets the LONG name for this {@code TimeZone} for the default {@code Locale} in standard time. If the name is not available, the result is in the format {@code GMT[+-]hh:mm}.
 public final String getDisplayName(Locale locale) 
    Gets the LONG name for this {@code TimeZone} for the specified {@code Locale} in standard time. If the name is not available, the result is in the format {@code GMT[+-]hh:mm}.
 public final String getDisplayName(boolean daylightTime,
    int style) 
    Gets the specified style of name ({@code LONG} or {@code SHORT}) for this {@code TimeZone} for the default {@code Locale} in either standard or daylight time as specified. If the name is not available, the result is in the format {@code GMT[+-]hh:mm}.
 public String getDisplayName(boolean daylightTime,
    int style,
    Locale locale) 
    Gets the specified style of name ({@code LONG} or {@code SHORT}) for this {@code TimeZone} for the specified {@code Locale} in either standard or daylight time as specified. If the name is not available, the result is in the format {@code GMT[+-]hh:mm}.
 public String getID() 
    Gets the ID of this {@code TimeZone}.
 public int getOffset(long time) 
    Gets the offset from GMT of this {@code TimeZone} for the specified date. The offset includes daylight savings time if the specified date is within the daylight savings time period.
 abstract public int getOffset(int era,
    int year,
    int month,
    int day,
    int dayOfWeek,
    int time)
    Gets the offset from GMT of this {@code TimeZone} for the specified date and time. The offset includes daylight savings time if the specified date and time are within the daylight savings time period.
 abstract public int getRawOffset()
    Gets the offset for standard time from GMT for this {@code TimeZone}.
 public static synchronized TimeZone getTimeZone(String name) 
    Gets the {@code TimeZone} with the specified ID.
 public boolean hasSameRules(TimeZone zone) 
    Returns whether the specified {@code TimeZone} has the same raw offset as this {@code TimeZone}.
 abstract public boolean inDaylightTime(Date time)
    Returns whether the specified {@code Date} is in the daylight savings time period for this {@code TimeZone}.
 public static synchronized  void setDefault(TimeZone timezone) 
    Sets the default time zone. If passed {@code null}, then the next time #getDefault is called, the default time zone will be determined. This behavior is slightly different than the canonical description of this method, but it follows the spirit of it.
 public  void setID(String name) 
    Sets the ID of this {@code TimeZone}.
 abstract public  void setRawOffset(int offset)
    Sets the offset for standard time from GMT for this {@code TimeZone}.
 abstract public boolean useDaylightTime()
    Returns whether this {@code TimeZone} has a daylight savings time period.