Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.util

Class TimeZone

java.lang.Object
|
+--java.util.TimeZone

All Implemented Interfaces:

Serializable, Cloneable


public abstract class TimeZone

extends Object

implements Serializable, Cloneable

This class represents a time zone offset and handles daylight savings. You can get the default time zone with getDefault. This represents the time zone where program is running. Another way to create a time zone is getTimeZone, where you can give an identifier as parameter. For instance, the identifier of the Central European Time zone is "CET". With the getAvailableIDs method, you can get all the supported time zone identifiers.

Author:See Also:

Field Summary

static intLONG

Constant used to indicate that a long timezone name should be returned, such as "Eastern Standard Time".
static intSHORT

Constant used to indicate that a short timezone abbreviation should be returned, such as "EST"

Method Summary

java.lang.Objectclone()

Returns a clone of this object.
static java.lang.String[]getAvailableIDs(int rawOffset)

Gets the available IDs according to the given time zone offset.
static java.lang.String[]getAvailableIDs()

Gets all available IDs.
intgetDSTSavings()

Gets the daylight savings offset.
static java.util.TimeZonegetDefault()

Returns the time zone under which the host is running.
java.lang.StringgetDisplayName()

This method returns a string name of the time zone suitable for displaying to the user.
java.lang.StringgetDisplayName(java.util.Locale locale)

This method returns a string name of the time zone suitable for displaying to the user.
java.lang.StringgetDisplayName(boolean dst, int style)

This method returns a string name of the time zone suitable for displaying to the user.
java.lang.StringgetDisplayName(boolean dst, int style, java.util.Locale locale)

This method returns a string name of the time zone suitable for displaying to the user.
java.lang.StringgetID()

Gets the identifier of this time zone.
intgetOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds)

Gets the time zone offset, for current date, modified in case of daylight savings.
intgetRawOffset()

Gets the time zone offset, ignoring daylight savings.
static java.util.TimeZonegetTimeZone(java.lang.String ID)

Gets the TimeZone for the given ID.
booleanhasSameRules(java.util.TimeZone other)

Test if the other time zone uses the same rule and only possibly differs in ID.
booleaninDaylightTime(java.util.Date date)

Returns true, if the given date is in Daylight Savings Time in this time zone.
static voidsetDefault(java.util.TimeZone zone)

voidsetID(java.lang.String id)

Sets the identifier of this time zone.
voidsetRawOffset(int offsetMillis)

Sets the time zone offset, ignoring daylight savings.
booleanuseDaylightTime()

Returns true, if this time zone uses Daylight Savings Time.

Field Details

LONG

public static final int LONG

Constant used to indicate that a long timezone name should be returned, such as "Eastern Standard Time".


SHORT

public static final int SHORT

Constant used to indicate that a short timezone abbreviation should be returned, such as "EST"


Method Details

clone

public Object clone()

Returns a clone of this object. I can't imagine, why this is useful for a time zone.


getAvailableIDs

public static String[] getAvailableIDs()

Gets all available IDs.

Returns:


getAvailableIDs

public static String[] getAvailableIDs(int rawOffset)

Gets the available IDs according to the given time zone offset.

Parameters:

Returns:


getDSTSavings

public int getDSTSavings()

Gets the daylight savings offset. This is a positive offset in milliseconds with respect to standard time. Typically this is one hour, but for some time zones this may be half an our.

The default implementation returns 3600000 milliseconds (one hour) if the time zone uses daylight savings time (as specified by #useDaylightTime()), otherwise it returns 0.

Since:Returns:


getDefault

public static TimeZone getDefault()

Returns the time zone under which the host is running. This can be changed with setDefault.

Returns:

See Also:


getDisplayName

public final String getDisplayName()

This method returns a string name of the time zone suitable for displaying to the user. The string returned will be the long description of the timezone in the current locale. The name displayed will assume daylight savings time is not in effect.

Returns:


getDisplayName

public final String getDisplayName(boolean dst, int style)

This method returns a string name of the time zone suitable for displaying to the user. The string returned will be of the specified type in the current locale.

Parameters:

Returns:


getDisplayName

public String getDisplayName(boolean dst, int style, java.util.Locale locale)

This method returns a string name of the time zone suitable for displaying to the user. The string returned will be of the specified type in the specified locale.

Parameters:

Returns:


getDisplayName

public final String getDisplayName(java.util.Locale locale)

This method returns a string name of the time zone suitable for displaying to the user. The string returned will be the long description of the timezone in the specified locale. The name displayed will assume daylight savings time is not in effect.

Parameters:

Returns:


getID

public String getID()

Gets the identifier of this time zone. For instance, PST for Pacific Standard Time.


getOffset

public int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds)

Gets the time zone offset, for current date, modified in case of daylight savings. This is the offset to add to UTC to get the local time.

Parameters:

Returns:


getRawOffset

public int getRawOffset()

Gets the time zone offset, ignoring daylight savings. This is the offset to add to UTC to get the local time.

Returns:


getTimeZone

public static TimeZone getTimeZone(java.lang.String ID)

Gets the TimeZone for the given ID.

Parameters:

Returns:


hasSameRules

public boolean hasSameRules(java.util.TimeZone other)

Test if the other time zone uses the same rule and only possibly differs in ID. This implementation for this particular class will return true if the raw offsets are identical. Subclasses should override this method if they use daylight savings.

Parameters:

Returns:


inDaylightTime

public boolean inDaylightTime(java.util.Date date)

Returns true, if the given date is in Daylight Savings Time in this time zone.

Parameters:


setDefault

public static void setDefault(java.util.TimeZone zone)

Parameters:


setID

public void setID(java.lang.String id)

Sets the identifier of this time zone. For instance, PST for Pacific Standard Time.

Parameters:


setRawOffset

public void setRawOffset(int offsetMillis)

Sets the time zone offset, ignoring daylight savings. This is the offset to add to UTC to get the local time.

Parameters:


useDaylightTime

public boolean useDaylightTime()

Returns true, if this time zone uses Daylight Savings Time.