Class TTimeZone
- All Implemented Interfaces:
Serializable,Cloneable
TimeZone represents a time zone offset, taking into account
daylight savings.
Typically, you get a TimeZone using getDefault
which creates a TimeZone based on the time zone where the
program is running. For example, for a program running in Japan,
getDefault creates a TimeZone object based on
Japanese Standard Time.
You can also get a TimeZone using 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 TimeZone object with the following:
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
You can use the getAvailableIDs method to iterate
through all the supported time zone IDs. You can then choose a supported ID
to get a 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: For example, you might specify GMT+14:00 as a custom time zone ID. TheGMT[+|-]hh[[:]mm]
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. getDefault()
and getTimeZone(String), is implementation dependent, so it may
introduce serialization incompatibility issues between different
implementations.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Returns a newTimeZonewith the same ID,rawOffsetand daylight savings time rules as thisTimeZone.booleanstatic String[]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 TTimeZoneGets the default time zone.final StringGets the LONG name for thisTimeZonefor the defaultLocalein standard time.final StringgetDisplayName(boolean daylightTime, int style) Gets the specified style of name (LONGorSHORT) for thisTimeZonefor the defaultLocalein either standard or daylight time as specified.getDisplayName(boolean daylightTime, int style, TLocale locale) Gets the specified style of name (LONGorSHORT) for thisTimeZonefor the specifiedLocalein either standard or daylight time as specified.final StringgetDisplayName(TLocale locale) Gets the LONG name for thisTimeZonefor the specifiedLocalein standard time.intGets the daylight savings offset in milliseconds for thisTimeZone.getID()Gets the ID of thisTimeZone.abstract intgetOffset(int era, int year, int month, int day, int dayOfWeek, int time) Gets the offset from GMT of thisTimeZonefor the specified date and time.intgetOffset(long time) Gets the offset from GMT of thisTimeZonefor the specified date.abstract intGets the offset for standard time from GMT for thisTimeZone.static TTimeZonegetTimeZone(String name) Gets theTimeZonewith the specified ID.inthashCode()booleanhasSameRules(TTimeZone zone) Returns whether the specifiedTimeZonehas the same raw offset as thisTimeZone.abstract booleaninDaylightTime(TDate time) Returns whether the specifiedDateis in the daylight savings time period for thisTimeZone.static voidsetDefault(TTimeZone timezone) Sets the default time zone.voidSets the ID of thisTimeZone.abstract voidsetRawOffset(int offset) Sets the offset for standard time from GMT for thisTimeZone.abstract booleanReturns whether thisTimeZonehas a daylight savings time period.
-
Field Details
-
SHORT
public static final int SHORTThe SHORT display name style.- See Also:
-
LONG
public static final int LONGThe LONG display name style.- See Also:
-
-
Constructor Details
-
TTimeZone
public TTimeZone()Constructs a new instance of this class.
-
-
Method Details
-
clone
Returns a newTimeZonewith the same ID,rawOffsetand daylight savings time rules as thisTimeZone. -
getAvailableIDs
Gets the available time zone IDs. Any one of these IDs can be passed toget()to create the correspondingTimeZoneinstance.- Returns:
- an array of time zone ID strings.
-
getAvailableIDs
Gets the available time zone IDs which match the specified offset from GMT. Any one of these IDs can be passed toget()to create the correspondingTimeZoneinstance.- Parameters:
offset- the offset from GMT in milliseconds.- Returns:
- an array of time zone ID strings.
-
getDefault
Gets the default time zone.- Returns:
- the default time zone.
-
getDisplayName
Gets the LONG name for thisTimeZonefor the defaultLocalein standard time. If the name is not available, the result is in the formatGMT[+-]hh:mm.- Returns:
- the
TimeZonename.
-
getDisplayName
Gets the LONG name for thisTimeZonefor the specifiedLocalein standard time. If the name is not available, the result is in the formatGMT[+-]hh:mm.- Parameters:
locale- theLocale.- Returns:
- the
TimeZonename.
-
getDisplayName
Gets the specified style of name (LONGorSHORT) for thisTimeZonefor the defaultLocalein either standard or daylight time as specified. If the name is not available, the result is in the formatGMT[+-]hh:mm.- Parameters:
daylightTime-truefor daylight time,falsefor standard time.style- eitherLONGorSHORT.- Returns:
- the
TimeZonename.
-
getDisplayName
Gets the specified style of name (LONGorSHORT) for thisTimeZonefor the specifiedLocalein either standard or daylight time as specified. If the name is not available, the result is in the formatGMT[+-]hh:mm.- Parameters:
daylightTime-truefor daylight time,falsefor standard time.style- either LONG or SHORT.locale- eitherLONGorSHORT.- Returns:
- the
TimeZonename.
-
getID
Gets the ID of thisTimeZone.- Returns:
- the time zone ID string.
-
getDSTSavings
public int getDSTSavings()Gets the daylight savings offset in milliseconds for thisTimeZone.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
TimeZoneobserves daylight savings, zero otherwise.
-
getOffset
public int getOffset(long time) Gets the offset from GMT of thisTimeZonefor 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 thisTimeZonefor 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- theGregorianCalendarera, eitherGregorianCalendar.BCorGregorianCalendar.AD.year- the year.month- theCalendarmonth.day- the day of the month.dayOfWeek- theCalendarday 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 thisTimeZone.- Returns:
- the offset from GMT in milliseconds.
-
getTimeZone
Gets theTimeZonewith the specified ID.- Parameters:
name- a time zone string ID.- Returns:
- the
TimeZonewith the specified ID or null if noTimeZonewith the specified ID exists.
-
hasSameRules
Returns whether the specifiedTimeZonehas the same raw offset as thisTimeZone.- Parameters:
zone- aTimeZone.- Returns:
truewhen theTimeZonehave the same raw offset,falseotherwise.
-
inDaylightTime
Returns whether the specifiedDateis in the daylight savings time period for thisTimeZone.- Parameters:
time- aDate.- Returns:
truewhen theDateis in the daylight savings time period,falseotherwise.
-
setDefault
Sets the default time zone. If passednull, then the next timegetDefault()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.- Parameters:
timezone- aTimeZoneobject.
-
setID
Sets the ID of thisTimeZone.- 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 thisTimeZone.- Parameters:
offset- the offset from GMT in milliseconds.
-
useDaylightTime
public abstract boolean useDaylightTime()Returns whether thisTimeZonehas a daylight savings time period.- Returns:
trueif thisTimeZonehas a daylight savings time period,falseotherwise.
-
equals
-
hashCode
public int hashCode()
-