java.util
public abstract class TimeZone extends Object implements Serializable, Cloneable
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.Calendar
,
SimpleTimeZone
,
Serialized FormModifier and Type | Field and Description |
---|---|
static int |
LONG
Constant used to indicate that a long timezone name should be
returned, such as "Eastern Standard Time".
|
static int |
SHORT
Constant used to indicate that a short timezone abbreviation should
be returned, such as "EST"
|
Constructor and Description |
---|
TimeZone() |
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Returns a clone of this object.
|
static String[] |
getAvailableIDs()
Gets all available IDs.
|
static String[] |
getAvailableIDs(int rawOffset)
Gets the available IDs according to the given time zone
offset.
|
static TimeZone |
getDefault()
Returns the time zone under which the host is running.
|
String |
getDisplayName()
This method returns a string name of the time zone suitable
for displaying to the user.
|
String |
getDisplayName(boolean dst,
int style)
This method returns a string name of the time zone suitable
for displaying to the user.
|
String |
getDisplayName(boolean dst,
int style,
Locale locale)
This method returns a string name of the time zone suitable
for displaying to the user.
|
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.
|
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(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.
|
static void |
setDefault(TimeZone zone) |
void |
setID(String id)
Sets the identifier of this time zone.
|
abstract void |
setRawOffset(int offsetMillis)
Sets the time zone offset, ignoring daylight savings.
|
abstract boolean |
useDaylightTime()
Returns true, if this time zone uses Daylight Savings Time.
|
public static final int SHORT
public static final int LONG
public TimeZone()
public abstract int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds)
era
- the era of the given dateyear
- the year of the given datemonth
- the month of the given date, 0 for January.day
- the day of monthdayOfWeek
- the day of weekmilliseconds
- the millis in the day (in local standard time)public int getOffset(long date)
date
- the date represented in millisecends
since January 1, 1970 00:00:00 GMT.public abstract int getRawOffset()
public abstract void setRawOffset(int offsetMillis)
offsetMillis
- the time zone offset to GMT.public String getID()
public void setID(String id)
id
- the new time zone ID.NullPointerException
- if id
is null
public final String getDisplayName()
public final String getDisplayName(Locale locale)
locale
- The locale for this timezone name.public final String getDisplayName(boolean dst, int style)
dst
- Whether or not daylight savings time is in effect.style
- LONG
for a long name, SHORT
for
a short abbreviation.public String getDisplayName(boolean dst, int style, Locale locale)
dst
- Whether or not daylight savings time is in effect.style
- LONG
for a long name, SHORT
for
a short abbreviation.locale
- The locale for this timezone name.public abstract boolean useDaylightTime()
public abstract boolean inDaylightTime(Date date)
date
- the given Date.public int getDSTSavings()
The default implementation returns 3600000 milliseconds
(one hour) if the time zone uses daylight savings time
(as specified by useDaylightTime()
), otherwise
it returns 0.
public static TimeZone getTimeZone(String ID)
ID
- the time zone identifier.public static String[] getAvailableIDs(int rawOffset)
rawOffset
- the given time zone GMT offset.{"Phoenix", "Denver"}
, since both have
GMT-07:00, but differ in daylight savings behaviour.public static String[] getAvailableIDs()
public static TimeZone getDefault()
setDefault(java.util.TimeZone)
public static void setDefault(TimeZone zone)
public boolean hasSameRules(TimeZone other)