|
|||||||||
| Home >> All >> java >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.util
Class TimeZone

java.lang.Objectjava.util.TimeZone
- All Implemented Interfaces:
- java.lang.Cloneable, java.io.Serializable
- Direct Known Subclasses:
- SimpleTimeZone
- public abstract class TimeZone
- extends java.lang.Object
- implements java.io.Serializable, java.lang.Cloneable
- extends java.lang.Object
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.
| Field Summary | |
private static TimeZone |
defaultZone0
The default time zone, as returned by getDefault. |
private java.lang.String |
ID
The time zone identifier, e.g. |
static int |
LONG
Constant used to indicate that a long timezone name should be returned, such as "Eastern Standard Time". |
private static long |
serialVersionUID
|
static int |
SHORT
Constant used to indicate that a short timezone abbreviation should be returned, such as "EST" |
private static HashMap |
timezones0
HashMap for timezones by ID. |
| Constructor Summary | |
TimeZone()
|
|
| Method Summary | |
java.lang.Object |
clone()
Returns a clone of this object. |
private static TimeZone |
defaultZone()
Tries to get the default TimeZone for this system if not already set. |
static java.lang.String[] |
getAvailableIDs()
Gets all available IDs. |
static java.lang.String[] |
getAvailableIDs(int rawOffset)
Gets the available IDs according to the given time zone offset. |
private static int[] |
getDateParams(java.lang.String date)
Parses and returns the params for a POSIX TZ date field, in the format int[]{ month, day, dayOfWeek }, following the SimpleTimeZone constructor rules. |
static TimeZone |
getDefault()
Returns the time zone under which the host is running. |
private java.lang.String |
getDefaultDisplayName(boolean dst)
|
(package private) static TimeZone |
getDefaultTimeZone(java.lang.String sysTimeZoneId)
Maps a time zone name (with optional GMT offset and daylight time zone name) to one of the known time zones. |
java.lang.String |
getDisplayName()
This method returns a string name of the time zone suitable for displaying to the user. |
java.lang.String |
getDisplayName(boolean dst,
int style)
This method returns a string name of the time zone suitable for displaying to the user. |
java.lang.String |
getDisplayName(boolean dst,
int style,
Locale locale)
This method returns a string name of the time zone suitable for displaying to the user. |
java.lang.String |
getDisplayName(Locale locale)
This method returns a string name of the time zone suitable for displaying to the user. |
int |
getDSTSavings()
Gets the daylight savings offset. |
java.lang.String |
getID()
Gets the identifier of this time zone. |
abstract 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. |
int |
getOffset(long date)
Get the time zone offset for the specified date, modified in case of daylight savings. |
abstract int |
getRawOffset()
Gets the time zone offset, ignoring daylight savings. |
static TimeZone |
getTimeZone(java.lang.String ID)
Gets the TimeZone for the given ID. |
boolean |
hasSameRules(TimeZone other)
Test if the other time zone uses the same rule and only possibly differs in ID. |
abstract boolean |
inDaylightTime(Date date)
Returns true, if the given date is in Daylight Savings Time in this time zone. |
private static int |
parseTime(java.lang.String time)
Parses a time field hh[:mm[:ss]], returning the result in milliseconds. |
static void |
setDefault(TimeZone zone)
|
void |
setID(java.lang.String id)
Sets the identifier of this time zone. |
abstract void |
setRawOffset(int offsetMillis)
Sets the time zone offset, ignoring daylight savings. |
(package private) static HashMap |
timezones()
|
abstract boolean |
useDaylightTime()
Returns true, if this time zone uses Daylight Savings Time. |
| 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
- Constant used to indicate that a short timezone abbreviation should
be returned, such as "EST"
- See Also:
- Constant Field Values
LONG
public static final int LONG
- Constant used to indicate that a long timezone name should be
returned, such as "Eastern Standard Time".
- See Also:
- Constant Field Values
ID
private java.lang.String ID
- The time zone identifier, e.g. PST.
defaultZone0
private static TimeZone defaultZone0
- The default time zone, as returned by getDefault.
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
timezones0
private static HashMap timezones0
- HashMap for timezones by ID.
| Constructor Detail |
TimeZone
public TimeZone()
| Method Detail |
defaultZone
private static TimeZone defaultZone()
- Tries to get the default TimeZone for this system if not already
set. It will call
getDefaultTimeZone(String)with the result ofSystem.getProperty("user.timezone"). If that fails it callsVMTimeZone.getDefaultTimeZoneId(). If that also fails GMT is returned.
timezones
static HashMap timezones()
getDefaultTimeZone
static TimeZone getDefaultTimeZone(java.lang.String sysTimeZoneId)
- Maps a time zone name (with optional GMT offset and daylight time
zone name) to one of the known time zones. This method called
with the result of
System.getProperty("user.timezone")orgetDefaultTimeZoneId(). Note that giving one of the standard tz data names from ftp://elsie.nci.nih.gov/pub/ is preferred. The time zone name can be given as follows:(standard zone name)[(GMT offset)[(DST zone name)[DST offset]]]If only a (standard zone name) is given (no numbers in the String) then it gets mapped directly to the TimeZone with that name, if that fails null is returned.
Alternately, a POSIX-style TZ string can be given, defining the time zone:
std offset dst offset,date/time,date/timeSee the glibc manual, or the man page fortzsetfor details of this format.A GMT offset is the offset to add to the local time to get GMT. If a (GMT offset) is included (either in seconds or hours) then an attempt is made to find a TimeZone name matching both the name and the offset (that doesn't observe daylight time, if the timezone observes daylight time then you must include a daylight time zone name after the offset), if that fails then a TimeZone with the given GMT offset is returned (whether or not the TimeZone observes daylight time is ignored), if that also fails the GMT TimeZone is returned.
If the String ends with (GMT offset)(daylight time zone name) then an attempt is made to find a TimeZone with the given name and GMT offset that also observes (the daylight time zone name is not currently used in any other way), if that fails a TimeZone with the given GMT offset that observes daylight time is returned, if that also fails the GMT TimeZone is returned.
Examples: In Chicago, the time zone id could be "CST6CDT", but the preferred name would be "America/Chicago". In Indianapolis (which does not have Daylight Savings Time) the string could be "EST5", but the preferred name would be "America/Indianapolis". The standard time zone name for The Netherlands is "Europe/Amsterdam", but can also be given as "CET-1CEST".
getDateParams
private static int[] getDateParams(java.lang.String date)
- Parses and returns the params for a POSIX TZ date field,
in the format int[]{ month, day, dayOfWeek }, following the
SimpleTimeZone constructor rules.
parseTime
private static int parseTime(java.lang.String time)
- Parses a time field hh[:mm[:ss]], returning the result
in milliseconds. No leading sign.
getOffset
public abstract 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.
getOffset
public int getOffset(long date)
- Get the time zone offset for the specified date, modified in case of
daylight savings. This is the offset to add to UTC to get the local
time.
- Since:
- 1.4
getRawOffset
public abstract int getRawOffset()
- Gets the time zone offset, ignoring daylight savings. This is
the offset to add to UTC to get the local time.
setRawOffset
public abstract 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.
getID
public java.lang.String getID()
- Gets the identifier of this time zone. For instance, PST for
Pacific Standard Time.
setID
public void setID(java.lang.String id)
- Sets the identifier of this time zone. For instance, PST for
Pacific Standard Time.
getDisplayName
public final java.lang.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.
getDisplayName
public final java.lang.String getDisplayName(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.
getDisplayName
public final java.lang.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.
getDisplayName
public java.lang.String getDisplayName(boolean dst, int style, 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.
getDefaultDisplayName
private java.lang.String getDefaultDisplayName(boolean dst)
useDaylightTime
public abstract boolean useDaylightTime()
- Returns true, if this time zone uses Daylight Savings Time.
inDaylightTime
public abstract boolean inDaylightTime(Date date)
- Returns true, if the given date is in Daylight Savings Time in this
time zone.
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()55 ), otherwise it returns 0.- Since:
- 1.4
getTimeZone
public static TimeZone getTimeZone(java.lang.String ID)
- Gets the TimeZone for the given ID.
getAvailableIDs
public static java.lang.String[] getAvailableIDs(int rawOffset)
- Gets the available IDs according to the given time zone
offset.
getAvailableIDs
public static java.lang.String[] getAvailableIDs()
- Gets all available IDs.
getDefault
public static TimeZone getDefault()
- Returns the time zone under which the host is running. This
can be changed with setDefault.
setDefault
public static void setDefault(TimeZone zone)
hasSameRules
public boolean hasSameRules(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.
clone
public java.lang.Object clone()
- Returns a clone of this object. I can't imagine, why this is
useful for a time zone.
|
|||||||||
| Home >> All >> java >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
java.util.TimeZone