Build 1.0_r1(from source)

java.util
Class TimeZone

java.lang.Object
  extended by java.util.TimeZone
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
SimpleTimeZone, ZoneInfo, ZoneInfoDB.MinimalTimeZone

public abstract class TimeZone
extends Object
implements Serializable, Cloneable

TimeZone is an abstract class which represents a local time zone and its daylight savings time rules. Subclasses support a particular calendar type, such as the gregorian calendar. Please note the type returned by factory methods, i.e. getDefault() and getTimeZone(String), is implementation dependent, so that it may introduce serialization incompatibility issue between different implementations. Harmony returns instance of SimpleTimeZone so that the bytes serialized by Harmony can be deserialized on other implementation successfully, but the reverse compatibility cannot be guaranteed.

See Also:
GregorianCalendar, SimpleTimeZone, Serialized Form

Field Summary
(package private) static TimeZone GMT
           
static int LONG
          The LONG display name style.
static int SHORT
          The SHORT display name style.
 
Constructor Summary
TimeZone()
          Constructs a new instance of this class.
 
Method Summary
 Object clone()
          Returns a new TimeZone with the same ID, rawOffset and daylight savings time rules as this TimeZone.
static String[] getAvailableIDs()
          Gets the available time zone IDs.
static String[] getAvailableIDs(int offset)
          Gets the available time zone IDs which match the specified offset from GMT.
static TimeZone getDefault()
          Gets the default time zone.
 String getDisplayName()
          Gets the LONG name for this TimeZone for the default Locale in standard time.
 String getDisplayName(boolean daylightTime, int style)
          Gets the specified style of name (LONG or SHORT) for this TimeZone for the default Locale in either standard or daylight time as specified.
 String getDisplayName(boolean daylightTime, int style, Locale locale)
          Gets the specified style of name (LONG or SHORT) for this TimeZone for the specified Locale in either standard or daylight time as specified.
 String getDisplayName(Locale locale)
          Gets the LONG name for this TimeZone for the specified Locale in standard time.
 int getDSTSavings()
          Gets the daylight savings offset in milliseconds for this TimeZone.
 String getID()
          Gets the ID of this TimeZone.
abstract  int getOffset(int era, int year, int month, int day, int dayOfWeek, int time)
          Gets the offset from GMT of this TimeZone for the specified date and time.
 int getOffset(long time)
          Gets the offset from GMT of this TimeZone for the specified date.
abstract  int getRawOffset()
          Gets the offset for standard time from GMT for this TimeZone.
static TimeZone getTimeZone(String name)
          Gets the time zone with the specified ID.
 boolean hasSameRules(TimeZone zone)
          Returns if the specified TimeZone has the same raw offset as this TimeZone.
abstract  boolean inDaylightTime(Date time)
          Returns if the specified Date is in the daylight savings time period for this TimeZone.
static void setDefault(TimeZone timezone)
          Sets the default time zone.
 void setID(String name)
          Sets the ID of this TimeZone.
abstract  void setRawOffset(int offset)
          Sets the offset for standard time from GMT for this TimeZone.
abstract  boolean useDaylightTime()
          Returns if this TimeZone has a daylight savings time period.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHORT

public static final int SHORT
The SHORT display name style.

See Also:
Constant Field Values

LONG

public static final int LONG
The LONG display name style.

See Also:
Constant Field Values

GMT

static TimeZone GMT
Constructor Detail

TimeZone

public TimeZone()
Constructs a new instance of this class.

Method Detail

clone

public Object clone()
Returns a new TimeZone with the same ID, rawOffset and daylight savings time rules as this TimeZone.

Overrides:
clone in class Object
Returns:
a shallow copy of this TimeZone
See Also:
Cloneable

getAvailableIDs

public static String[] getAvailableIDs()
Gets the available time zone IDs.

Returns:
an array of time zone ID strings

getAvailableIDs

public static String[] getAvailableIDs(int offset)
Gets the available time zone IDs which match the specified offset from GMT.

Parameters:
offset - the offset from GMT in milliseconds
Returns:
an array of time zone ID strings

getDefault

public static TimeZone getDefault()
Gets the default time zone.

Returns:
the default time zone

getDisplayName

public final String getDisplayName()
Gets the LONG name for this TimeZone for the default Locale in standard time. If the name is not available, the result is in the format GMT[+-]hh:mm.

Returns:
the TimeZone name

getDisplayName

public final String getDisplayName(Locale locale)
Gets the LONG name for this TimeZone for the specified Locale in standard time. If the name is not available, the result is in the format GMT[+-]hh:mm.

Parameters:
locale - the Locale
Returns:
the TimeZone name

getDisplayName

public final String getDisplayName(boolean daylightTime,
                                   int style)
Gets the specified style of name (LONG or SHORT) for this TimeZone for the default Locale in either standard or daylight time as specified. If the name is not available, the result is in the format GMT[+-]hh:mm.

Parameters:
daylightTime - true for daylight time, false for standard time
style - Either LONG or SHORT
Returns:
the TimeZone name

getDisplayName

public String getDisplayName(boolean daylightTime,
                             int style,
                             Locale locale)
Gets the specified style of name (LONG or SHORT) for this TimeZone for the specified Locale in either standard or daylight time as specified. If the name is not available, the result is in the format GMT[+-]hh:mm.

Parameters:
daylightTime - true for daylight time, false for standard time
style - Either LONG or SHORT
locale - the Locale
Returns:
the TimeZone name

getID

public String getID()
Gets the ID of this TimeZone.

Returns:
the time zone ID string

getDSTSavings

public int getDSTSavings()
Gets the daylight savings offset in milliseconds for this 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.

Returns:
the daylight savings offset in milliseconds if this TimeZone observes daylight savings, zero otherwise.

getOffset

public int getOffset(long time)
Gets the offset from GMT of this TimeZone for the specified date. The offset includes daylight savings time if the specified date is within the daylight savings time period.

Parameters:
time - the date in milliseconds since January 1, 1970 00:00:00 GMT
Returns:
the offset from GMT in milliseconds

getOffset

public abstract int getOffset(int era,
                              int year,
                              int month,
                              int day,
                              int dayOfWeek,
                              int time)
Gets the offset from GMT of this 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.

Parameters:
era - the GregorianCalendar era, either GregorianCalendar.BC or GregorianCalendar.AD
year - the year
month - the Calendar month
day - the day of the month
dayOfWeek - the Calendar day of the week
time - the time of day in milliseconds
Returns:
the offset from GMT in milliseconds

getRawOffset

public abstract int getRawOffset()
Gets the offset for standard time from GMT for this TimeZone.

Returns:
the offset from GMT in milliseconds

getTimeZone

public static TimeZone getTimeZone(String name)
Gets the time zone with the specified ID.

Parameters:
name - a time zone string ID
Returns:
the time zone with the specified ID or null if a time zone with the specified ID does not exist

hasSameRules

public boolean hasSameRules(TimeZone zone)
Returns if the specified TimeZone has the same raw offset as this TimeZone.

Parameters:
zone - a TimeZone
Returns:
true when the TimeZones have the same raw offset, false otherwise

inDaylightTime

public abstract boolean inDaylightTime(Date time)
Returns if the specified Date is in the daylight savings time period for this TimeZone.

Parameters:
time - a Date
Returns:
true when the Date is in the daylight savings time period, false otherwise

setDefault

public static void setDefault(TimeZone timezone)
Sets the default time zone. If passed null, then the next time getDefault() is called, the default time zone with be determined. This behavior is slightly different than the canonical description of this method, but it follows the spirit of it.

Parameters:
timezone - a TimeZone object

setID

public void setID(String name)
Sets the ID of this TimeZone.

Parameters:
name - a string which is the time zone ID

setRawOffset

public abstract void setRawOffset(int offset)
Sets the offset for standard time from GMT for this TimeZone.

Parameters:
offset - the offset from GMT in milliseconds

useDaylightTime

public abstract boolean useDaylightTime()
Returns if this TimeZone has a daylight savings time period.

Returns:
true if this time zone has a daylight savings time period, false otherwise

Build 1.0_r1(from source)

Please submit a feedback, bug or feature