Class SimpleTimeZone
- All Implemented Interfaces:
Freezable<TimeZone>, Serializable, Cloneable
java.util.SimpleTimeZone. Methods, fields, and other functionality specific to ICU are labeled '[icu]'.
SimpleTimeZone is a concrete subclass of TimeZone that represents a
time zone for use with a Gregorian calendar. This class does not handle historical changes.
Use a negative value for dayOfWeekInMonth to indicate that SimpleTimeZone
should count from the end of the month backwards. For example, if Daylight Savings Time
starts or ends at the last Sunday in a month, use dayOfWeekInMonth = -1 along with
dayOfWeek = Calendar.SUNDAY to specify the rule.
- Author:
- Deborah Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu
- See Also:
- Status:
- Stable ICU 2.0.
-
Nested Class Summary
Nested classes/interfaces inherited from class BasicTimeZone
BasicTimeZone.LocalOptionModifier and TypeClassDescriptionstatic enumMethods, fields, and other functionality specific to ICU are labeled '[icu]'. Options used byBasicTimeZone.getOffsetFromLocal(long, LocalOption, LocalOption, int[])to specify how to interpret an input time when it does not exist, or when it is ambiguous, around a time zone transition.Nested classes/interfaces inherited from class TimeZone
TimeZone.SystemTimeZoneTypeModifier and TypeClassDescriptionstatic enumMethods, fields, and other functionality specific to ICU are labeled '[icu]'. System time zone type constants used by filtering zones inTimeZone.getAvailableIDs(SystemTimeZoneType, String, Integer) -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intConstant for a mode of start or end time specified as local standard time.static final intConstant for a mode of start or end time specified as UTC.static final intConstant for a mode of start or end time specified as local wall time.Fields inherited from class BasicTimeZone
FORMER_LATTER_MASK, LOCAL_DST, LOCAL_FORMER, LOCAL_LATTER, LOCAL_STD, STD_DST_MASKModifier and TypeFieldDescriptionprotected static final intDeprecated.This API is ICU internal only.protected static final intDeprecated.This API is ICU internal only.protected static final intDeprecated.This API is ICU internal only.protected static final intDeprecated.This API is ICU internal only.protected static final intDeprecated.This API is ICU internal only.protected static final intDeprecated.This API is ICU internal only.Fields inherited from class TimeZone
GENERIC_LOCATION, GMT_ZONE, LONG, LONG_GENERIC, LONG_GMT, SHORT, SHORT_COMMONLY_USED, SHORT_GENERIC, SHORT_GMT, TIMEZONE_ICU, TIMEZONE_JDK, UNKNOWN_ZONE, UNKNOWN_ZONE_IDModifier and TypeFieldDescriptionstatic final int[icu] A style specifier forgetDisplayName()indicating a long name derived from the timezone's fallback name, such as "United States (Los Angeles)."static final TimeZone[icu] The immutable GMT (=UTC) time zone.static final intA style specifier forgetDisplayName()indicating a long name, such as "Pacific Standard Time."static final int[icu] A style specifier forgetDisplayName()indicating a long generic name, such as "Pacific Time."static final int[icu] A style specifier forgetDisplayName()indicating a long name derived from the timezone's offset, such as "GMT-08:00."static final intA style specifier forgetDisplayName()indicating a short name, such as "PST."static final int[icu] A style specifier forgetDisplayName()indicating a short name derived from the timezone's short standard or daylight timezone name ignoring commonlyUsed, such as "PDT."static final int[icu] A style specifier forgetDisplayName()indicating a short generic name, such as "PT."static final int[icu] A style specifier forgetDisplayName()indicating a short name derived from the timezone's offset, such as "-0800."static final int[icu] A time zone implementation type indicating ICU's own TimeZone used bygetTimeZone,setDefaultTimeZoneTypeandgetDefaultTimeZoneType.static final int[icu] A time zone implementation type indicating theTimeZoneused bygetTimeZone,setDefaultTimeZoneTypeandgetDefaultTimeZoneType.static final TimeZone[icu] The immutable (frozen) "unknown" time zone.static final String[icu] The time zone ID reserved for unknown time zone. -
Constructor Summary
ConstructorsConstructorDescriptionSimpleTimeZone(int rawOffset, String ID) Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID.SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime) Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, time to start and end the daylight time.SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime, int dstSavings) Constructor.SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int startTimeMode, int endMonth, int endDay, int endDayOfWeek, int endTime, int endTimeMode, int dstSavings) Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, time and its mode to start and end the daylight time. -
Method Summary
Modifier and TypeMethodDescriptionclone()Overrides clone.Provides for the clone operation.booleanOverrides equals.freeze()Freezes the object.intReturns the amount of time in ms that the clock is advanced during DST.getNextTransition(long base, boolean inclusive) [icu] Returns the first time zone transition after the base time.intgetOffset(int era, int year, int month, int day, int dayOfWeek, int millis) Gets the time zone offset, for current date, modified in case of daylight savings.intgetOffset(int era, int year, int month, int day, int dayOfWeek, int millis, int monthLength) Deprecated.This API is ICU internal only.voidgetOffsetFromLocal(long date, BasicTimeZone.LocalOption nonExistingTimeOpt, BasicTimeZone.LocalOption duplicatedTimeOpt, int[] offsets) [icu] Returns time zone offsets from local wall time.getPreviousTransition(long base, boolean inclusive) [icu] Returns the last time zone transition before the base time.intOverrides TimeZone Gets the GMT offset for this time zone.[icu] Returns the array ofTimeZoneRulewhich represents the rule of this time zone object.inthashCode()Overrides hashCode.booleanhasSameRules(TimeZone othr) Returns true if this zone has the same rules and offset as another zone.booleaninDaylightTime(Date date) Overrides TimeZone Queries if the give date is in Daylight Saving Time.booleanisFrozen()Determines whether the object has been frozen or not.booleanQueries if this time zone is in daylight saving time or will observe daylight saving time at any future time.voidsetDSTSavings(int millisSavedDuringDST) Sets the amount of time in ms that the clock is advanced during DST.voidsetEndRule(int month, int dayOfMonth, int time) Sets the DST end rule to a fixed date within a month.voidsetEndRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time) Sets the daylight savings ending rule.voidsetEndRule(int month, int dayOfMonth, int dayOfWeek, int time, boolean after) Sets the DST end rule to a weekday before or after a give date within a month, e.g., the first Monday on or after the 8th.voidSets the time zone ID.voidsetRawOffset(int offsetMillis) Overrides TimeZone Sets the base time zone offset to GMT.voidsetStartRule(int month, int dayOfMonth, int time) Sets the DST start rule to a fixed date within a month.voidsetStartRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time) Sets the daylight savings starting rule.voidsetStartRule(int month, int dayOfMonth, int dayOfWeek, int time, boolean after) Sets the DST start rule to a weekday before or after a give date within a month, e.g., the first Monday on or after the 8th.voidsetStartYear(int year) Sets the daylight savings starting year.toString()Returns a string representation of this object.booleanOverrides TimeZone Queries if this time zone uses Daylight Saving Time.Methods inherited from class BasicTimeZone
getLocalOptionValue, getSimpleTimeZoneRulesNear, getTimeZoneRules, hasEquivalentTransitions, hasEquivalentTransitionsModifier and TypeMethodDescriptionprotected static intDeprecated.This API is ICU internal only.getSimpleTimeZoneRulesNear(long date) [icu] Returns the array ofTimeZoneRulewhich represents the rule of this time zone object near the specified date.getTimeZoneRules(long start) [icu] Returns the array ofTimeZoneRulewhich represents the rule of this time zone object since the specified start time.booleanhasEquivalentTransitions(TimeZone tz, long start, long end) [icu] Checks if the time zone has equivalent transitions in the time range.booleanhasEquivalentTransitions(TimeZone tz, long start, long end, boolean ignoreDstAmount) [icu] Checks if the time zone has equivalent transitions in the time range.Methods inherited from class TimeZone
countEquivalentIDs, forLocaleOrDefault, forULocaleOrDefault, getAvailableIDs, getAvailableIDs, getAvailableIDs, getAvailableIDs, getCanonicalID, getCanonicalID, getDefault, getDefaultTimeZoneType, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getEquivalentID, getFrozenTimeZone, getIanaID, getID, getIDForWindowsID, getOffset, getOffset, getRegion, getTimeZone, getTimeZone, getTZDataVersion, getWindowsID, setDefault, setDefaultTimeZoneType, setICUDefaultModifier and TypeMethodDescriptionstatic int[icu] Returns the number of IDs in the equivalency group that includes the given ID.static TimeZoneforLocaleOrDefault(Locale locale) Deprecated.This API is ICU internal only.static TimeZoneforULocaleOrDefault(ULocale locale) Deprecated.This API is ICU internal only.static String[]Return a new String array containing all system TimeZone IDs.static String[]getAvailableIDs(int rawOffset) Return a new String array containing all system TimeZone IDs with the given raw offset from GMT.getAvailableIDs(TimeZone.SystemTimeZoneType zoneType, String region, Integer rawOffset) [icu] Returns a set of time zone ID strings with the given filter conditions.static String[]getAvailableIDs(String country) Return a new String array containing all system TimeZone IDs associated with the given country.static StringgetCanonicalID(String id) [icu] Returns the canonical system time zone ID or the normalized custom time zone ID for the given time zone ID.static StringgetCanonicalID(String id, boolean[] isSystemID) [icu] Returns the canonical system time zone ID or the normalized custom time zone ID for the given time zone ID.static TimeZoneGets the defaultTimeZonefor this host.static int[icu] Returns the default time zone type currently used.final StringReturns a name of this time zone suitable for presentation to the user in the defaultDISPLAYlocale.final StringgetDisplayName(boolean daylight, int style) Returns a name of this time zone suitable for presentation to the user in the defaultDISPLAYlocale.getDisplayName(boolean daylight, int style, ULocale locale) Returns a name of this time zone suitable for presentation to the user in the specified locale.getDisplayName(boolean daylight, int style, Locale locale) Returns a name of this time zone suitable for presentation to the user in the specified locale.final StringgetDisplayName(ULocale locale) Returns a name of this time zone suitable for presentation to the user in the specified locale.final StringgetDisplayName(Locale locale) Returns a name of this time zone suitable for presentation to the user in the specified locale.static StringgetEquivalentID(String id, int index) Returns an ID in the equivalency group that includes the given ID.static TimeZoneGets theTimeZonefor the given ID.static StringReturns the preferred time zone ID in the IANA database for the given time zone ID.getID()Gets the ID of this time zone.static StringgetIDForWindowsID(String winid, String region) [icu] Converts a Windows time zone ID to an equivalent system time zone ID for a region.intgetOffset(long date) Returns the offset of this time zone from UTC at the specified date.voidgetOffset(long date, boolean local, int[] offsets) Returns the time zone raw and GMT offset for the given moment in time.static String[icu] Returns the region code associated with the given system time zone ID.static TimeZonegetTimeZone(String ID) Gets theTimeZonefor the given ID.static TimeZonegetTimeZone(String ID, int type) Gets theTimeZonefor the given ID and the timezone type.static String[icu] Returns the time zone data version currently used by ICU.static StringgetWindowsID(String id) [icu] Converts a system time zone ID to an equivalent Windows time zone ID.static voidsetDefault(TimeZone tz) Sets theTimeZonethat is returned by thegetDefaultmethod.static voidsetDefaultTimeZoneType(int type) Sets the default time zone type used bygetTimeZone.static voidDeprecated.This API is ICU internal only.
-
Field Details
-
WALL_TIME
public static final int WALL_TIMEConstant for a mode of start or end time specified as local wall time.- See Also:
- Status:
- Stable ICU 3.8.
-
STANDARD_TIME
public static final int STANDARD_TIMEConstant for a mode of start or end time specified as local standard time.- See Also:
- Status:
- Stable ICU 3.8.
-
UTC_TIME
public static final int UTC_TIMEConstant for a mode of start or end time specified as UTC.- See Also:
- Status:
- Stable ICU 3.8.
-
-
Constructor Details
-
SimpleTimeZone
Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID. Timezone IDs can be obtained from TimeZone.getAvailableIDs. Normally you should use TimeZone.getDefault to construct a TimeZone.- Parameters:
rawOffset- The given base time zone offset to GMT.ID- The time zone ID which is obtained from TimeZone.getAvailableIDs.- Status:
- Stable ICU 2.0.
-
SimpleTimeZone
public SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime) Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, time to start and end the daylight time. Timezone IDs can be obtained from TimeZone.getAvailableIDs. Normally you should use TimeZone.getDefault to create a TimeZone. For a time zone that does not use daylight saving time, do not use this constructor; instead you should use SimpleTimeZone(rawOffset, ID).By default, this constructor specifies day-of-week-in-month rules. That is, if the startDay is 1, and the startDayOfWeek is SUNDAY, then this indicates the first Sunday in the startMonth. A startDay of -1 likewise indicates the last Sunday. However, by using negative or zero values for certain parameters, other types of rules can be specified.
Day of month. To specify an exact day of the month, such as March 1, set startDayOfWeek to zero.
Day of week after day of month. To specify the first day of the week occurring on or after an exact day of the month, make the day of the week negative. For example, if startDay is 5 and startDayOfWeek is -MONDAY, this indicates the first Monday on or after the 5th day of the startMonth.
Day of week before day of month. To specify the last day of the week occurring on or before an exact day of the month, make the day of the week and the day of the month negative. For example, if startDay is -21 and startDayOfWeek is -WEDNESDAY, this indicates the last Wednesday on or before the 21st of the startMonth.
The above examples refer to the startMonth, startDay, and startDayOfWeek; the same applies for the endMonth, endDay, and endDayOfWeek.
- Parameters:
rawOffset- The given base time zone offset to GMT.ID- The time zone ID which is obtained from TimeZone.getAvailableIDs.startMonth- The daylight savings starting month. Month is 0-based. eg, 0 for January.startDay- The daylight savings starting day-of-week-in-month. Please see the member description for an example.startDayOfWeek- The daylight savings starting day-of-week. Please see the member description for an example.startTime- The daylight savings starting time in local wall time, which is standard time in this case. Please see the member description for an example.endMonth- The daylight savings ending month. Month is 0-based. eg, 0 for January.endDay- The daylight savings ending day-of-week-in-month. Please see the member description for an example.endDayOfWeek- The daylight savings ending day-of-week. Please see the member description for an example.endTime- The daylight savings ending time in local wall time, which is daylight time in this case. Please see the member description for an example.- Throws:
IllegalArgumentException- the month, day, dayOfWeek, or time parameters are out of range for the start or end rule- Status:
- Stable ICU 2.0.
-
SimpleTimeZone
public SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int startTimeMode, int endMonth, int endDay, int endDayOfWeek, int endTime, int endTimeMode, int dstSavings) Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, time and its mode to start and end the daylight time. The mode specifies eitherWALL_TIMEorSTANDARD_TIMEorUTC_TIME.- Parameters:
rawOffset- The given base time zone offset to GMT.ID- The time zone ID which is obtained from TimeZone.getAvailableIDs.startMonth- The daylight savings starting month. Month is 0-based. eg, 0 for January.startDay- The daylight savings starting day-of-week-in-month. Please see the member description for an example.startDayOfWeek- The daylight savings starting day-of-week. Please see the member description for an example.startTime- The daylight savings starting time in local wall time, which is standard time in this case. Please see the member description for an example.startTimeMode- The mode of the start time specified by startTime.endMonth- The daylight savings ending month. Month is 0-based. eg, 0 for January.endDay- The daylight savings ending day-of-week-in-month. Please see the member description for an example.endDayOfWeek- The daylight savings ending day-of-week. Please see the member description for an example.endTime- The daylight savings ending time in local wall time, which is daylight time in this case. Please see the member description for an example.endTimeMode- The mode of the end time specified by endTime.dstSavings- The amount of time in ms saved during DST.- Throws:
IllegalArgumentException- the month, day, dayOfWeek, or time parameters are out of range for the start or end rule- Status:
- Stable ICU 3.8.
-
SimpleTimeZone
public SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime, int dstSavings) Constructor. This constructor is identical to the 10-argument constructor, but also takes a dstSavings parameter.- Parameters:
rawOffset- The given base time zone offset to GMT.ID- The time zone ID which is obtained from TimeZone.getAvailableIDs.startMonth- The daylight savings starting month. Month is 0-based. eg, 0 for January.startDay- The daylight savings starting day-of-week-in-month. Please see the member description for an example.startDayOfWeek- The daylight savings starting day-of-week. Please see the member description for an example.startTime- The daylight savings starting time in local wall time, which is standard time in this case. Please see the member description for an example.endMonth- The daylight savings ending month. Month is 0-based. eg, 0 for January.endDay- The daylight savings ending day-of-week-in-month. Please see the member description for an example.endDayOfWeek- The daylight savings ending day-of-week. Please see the member description for an example.endTime- The daylight savings ending time in local wall time, which is daylight time in this case. Please see the member description for an example.dstSavings- The amount of time in ms saved during DST.- Throws:
IllegalArgumentException- the month, day, dayOfWeek, or time parameters are out of range for the start or end rule- Status:
- Stable ICU 2.0.
-
-
Method Details
-
setID
-
setRawOffset
public void setRawOffset(int offsetMillis) Overrides TimeZone Sets the base time zone offset to GMT. This is the offset to add "to" UTC to get local time.- Specified by:
setRawOffsetin classTimeZone- Parameters:
offsetMillis- the raw offset of the time zone- Status:
- Stable ICU 2.0.
-
getRawOffset
public int getRawOffset()Overrides TimeZone Gets the GMT offset for this time zone.- Specified by:
getRawOffsetin classTimeZone- Returns:
- the raw offset
- Status:
- Stable ICU 2.0.
-
setStartYear
public void setStartYear(int year) Sets the daylight savings starting year.- Parameters:
year- The daylight savings starting year.- Status:
- Stable ICU 2.0.
-
setStartRule
public void setStartRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time) Sets the daylight savings starting rule. For example, Daylight Savings Time starts at the second Sunday in March, at 2 AM in standard time. Therefore, you can set the start rule by calling: setStartRule(Calendar.MARCH, 2, Calendar.SUNDAY, 2*60*60*1000);- Parameters:
month- The daylight savings starting month. Month is 0-based. eg, 0 for January.dayOfWeekInMonth- The daylight savings starting day-of-week-in-month. Please see the member description for an example.dayOfWeek- The daylight savings starting day-of-week. Please see the member description for an example.time- The daylight savings starting time in local wall time, which is standard time in this case. Please see the member description for an example.- Throws:
IllegalArgumentException- the month, dayOfWeekInMonth, dayOfWeek, or time parameters are out of range- Status:
- Stable ICU 2.0.
-
setStartRule
public void setStartRule(int month, int dayOfMonth, int time) Sets the DST start rule to a fixed date within a month.- Parameters:
month- The month in which this rule occurs (0-based).dayOfMonth- The date in that month (1-based).time- The time of that day (number of millis after midnight) when DST takes effect in local wall time, which is standard time in this case.- Throws:
IllegalArgumentException- the month, dayOfMonth, or time parameters are out of range- Status:
- Stable ICU 2.0.
-
setStartRule
public void setStartRule(int month, int dayOfMonth, int dayOfWeek, int time, boolean after) Sets the DST start rule to a weekday before or after a give date within a month, e.g., the first Monday on or after the 8th.- Parameters:
month- The month in which this rule occurs (0-based).dayOfMonth- A date within that month (1-based).dayOfWeek- The day of the week on which this rule occurs.time- The time of that day (number of millis after midnight) when DST takes effect in local wall time, which is standard time in this case.after- If true, this rule selects the first dayOfWeek on or after dayOfMonth. If false, this rule selects the last dayOfWeek on or before dayOfMonth.- Throws:
IllegalArgumentException- the month, dayOfMonth, dayOfWeek, or time parameters are out of range- Status:
- Stable ICU 2.0.
-
setEndRule
public void setEndRule(int month, int dayOfWeekInMonth, int dayOfWeek, int time) Sets the daylight savings ending rule. For example, if Daylight Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time, you can set the end rule by calling:setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000);- Parameters:
month- The daylight savings ending month. Month is 0-based. eg, 0 for January.dayOfWeekInMonth- The daylight savings ending day-of-week-in-month. Please see the member description for an example.dayOfWeek- The daylight savings ending day-of-week. Please see the member description for an example.time- The daylight savings ending time in local wall time, which is daylight time in this case. Please see the member description for an example.- Throws:
IllegalArgumentException- the month, dayOfWeekInMonth, dayOfWeek, or time parameters are out of range- Status:
- Stable ICU 2.0.
-
setEndRule
public void setEndRule(int month, int dayOfMonth, int time) Sets the DST end rule to a fixed date within a month.- Parameters:
month- The month in which this rule occurs (0-based).dayOfMonth- The date in that month (1-based).time- The time of that day (number of millis after midnight) when DST ends in local wall time, which is daylight time in this case.- Throws:
IllegalArgumentException- the month, dayOfMonth, or time parameters are out of range- Status:
- Stable ICU 2.0.
-
setEndRule
public void setEndRule(int month, int dayOfMonth, int dayOfWeek, int time, boolean after) Sets the DST end rule to a weekday before or after a give date within a month, e.g., the first Monday on or after the 8th.- Parameters:
month- The month in which this rule occurs (0-based).dayOfMonth- A date within that month (1-based).dayOfWeek- The day of the week on which this rule occurs.time- The time of that day (number of millis after midnight) when DST ends in local wall time, which is daylight time in this case.after- If true, this rule selects the first dayOfWeek on or after dayOfMonth. If false, this rule selects the last dayOfWeek on or before dayOfMonth.- Throws:
IllegalArgumentException- the month, dayOfMonth, dayOfWeek, or time parameters are out of range- Status:
- Stable ICU 2.0.
-
setDSTSavings
public void setDSTSavings(int millisSavedDuringDST) Sets the amount of time in ms that the clock is advanced during DST.- Parameters:
millisSavedDuringDST- the number of milliseconds the time is advanced with respect to standard time when the daylight savings rules are in effect. Typically one hour (+3600000). The amount could be negative, but not 0.- Status:
- Stable ICU 2.0.
-
getDSTSavings
public int getDSTSavings()Returns the amount of time in ms that the clock is advanced during DST.- Overrides:
getDSTSavingsin classTimeZone- Returns:
- the number of milliseconds the time is advanced with respect to standard time when the daylight savings rules are in effect. Typically one hour (3600000). The amount could be negative, but not 0.
- Status:
- Stable ICU 2.0.
-
toString
-
getOffset
public int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis) Gets the time zone offset, for current date, modified in case of daylight savings. This is the offset to add to UTC to get local time.- Specified by:
getOffsetin classTimeZone- Parameters:
era- the era of the given date.year- the year in the given date.month- the month in the given date. Month is 0-based. e.g., 0 for January.day- the day-in-month of the given date.dayOfWeek- the day-of-week of the given date.millis- the millis in day in standard local time.- Returns:
- the offset to add to GMT to get local time.
- Status:
- Stable ICU 2.0.
-
getOffset
@Deprecated public int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis, int monthLength) Deprecated.This API is ICU internal only.- Status:
- Internal. This API is ICU internal only.
-
getOffsetFromLocal
public void getOffsetFromLocal(long date, BasicTimeZone.LocalOption nonExistingTimeOpt, BasicTimeZone.LocalOption duplicatedTimeOpt, int[] offsets) [icu] Returns time zone offsets from local wall time.- Overrides:
getOffsetFromLocalin classBasicTimeZone- Status:
- Stable ICU 69.
-
useDaylightTime
public boolean useDaylightTime()Overrides TimeZone Queries if this time zone uses Daylight Saving Time.- Specified by:
useDaylightTimein classTimeZone- Returns:
- true if this time zone uses daylight savings time, false, otherwise.
Note:The default implementation of ICU TimeZone uses the tz database, which supports historic rule changes, for system time zones. With the implementation, there are time zones that used daylight savings time in the past, but no longer used currently. For example, Asia/Tokyo has never used daylight savings time since 1951. Most clients would expect that this method to return
falsefor such case. The default implementation of this method returnstruewhen the time zone uses daylight savings time in the current (Gregorian) calendar year. - Status:
- Stable ICU 2.0.
-
observesDaylightTime
public boolean observesDaylightTime()Queries if this time zone is in daylight saving time or will observe daylight saving time at any future time.The default implementation in this class returns
trueifTimeZone.useDaylightTime()orinDaylightTime(new Date())returnstrue.Note: This method was added for
TimeZonecompatibility support. TheTimeZone.useDaylightTime()method only checks the last known rule(s), therefore it may return false even the zone observes daylight saving time currently.TimeZoneaddedobservesDaylightTime()to resolve the issue. In ICU,TimeZone.useDaylightTime()works differently. The ICU implementation checks if the zone uses daylight saving time in the current calendar year. Therefore, it will never returnfalseif daylight saving time is currently used.ICU's TimeZone subclass implementations override this method to support the same behavior with
TimeZone.observesDaylightTime(). UnlikeTimeZone.useDaylightTime(), the implementation does not take past daylight saving time into account, so that this method may returnfalseeven whenTimeZone.useDaylightTime()returnstrue.- Overrides:
observesDaylightTimein classTimeZone- Returns:
trueif this time zone is in daylight saving time or will observe daylight saving time at any future time.- See Also:
- Status:
- Stable ICU 49.
-
inDaylightTime
Overrides TimeZone Queries if the give date is in Daylight Saving Time.- Specified by:
inDaylightTimein classTimeZone- Parameters:
date- the given Date.- Returns:
- true if the given date is in daylight savings time, false, otherwise.
- Status:
- Stable ICU 2.0.
-
equals
-
hashCode
-
clone
Overrides clone. -
hasSameRules
Returns true if this zone has the same rules and offset as another zone.- Overrides:
hasSameRulesin classTimeZone- Parameters:
othr- the TimeZone object to be compared with- Returns:
- true if the given zone has the same rules and offset as this one
- Status:
- Stable ICU 2.0.
-
getNextTransition
[icu] Returns the first time zone transition after the base time.Example code:
System.out.println("### Iterates time zone transitions in America/Los_Angeles starting 2005-01-01 and forward"); // A TimeZone instance created by getTimeZone with TIMEZONE_ICU is always a BasicTimeZone BasicTimeZone btz = (BasicTimeZone)TimeZone.getTimeZone("America/Los_Angeles", TimeZone.TIMEZONE_ICU); // Date format for the wall time SimpleDateFormat wallTimeFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z", ULocale.US); wallTimeFmt.setTimeZone(btz); long start = 1104537600000L; // 2005-01-01 0:00 UTC for (int i = 0; i < 5; i++) { // Up to 5 transitions TimeZoneTransition trans = btz.getNextTransition(start, false /* not including start time */); // Display the transition time and offset information long transTime = trans.getTime(); System.out.println(wallTimeFmt.format(new Date(transTime - 1)) + " -> " + wallTimeFmt.format(new Date(transTime))); System.out.println(" - Before (Offset/Save): " + trans.getFrom().getRawOffset() + "/" + trans.getFrom().getDSTSavings()); System.out.println(" - After (Offset/Save): " + trans.getTo().getRawOffset() + "/" + trans.getTo().getDSTSavings()); // Update start time for next transition start = transTime; }- Specified by:
getNextTransitionin classBasicTimeZone- Parameters:
base- The base time.inclusive- Whether the base time is inclusive or not.- Returns:
- A
Dateholding the first time zone transition time after the given base time, or null if no time zone transitions are available after the base time. - Status:
- Stable ICU 3.8.
-
getPreviousTransition
[icu] Returns the last time zone transition before the base time.Example code:
System.out.println("### Iterates time zone transitions in America/Los_Angeles starting 2010-01-01 and backward"); // A TimeZone instance created by getTimeZone with TIMEZONE_ICU is always a BasicTimeZone BasicTimeZone btz = (BasicTimeZone)TimeZone.getTimeZone("America/Los_Angeles", TimeZone.TIMEZONE_ICU); // Date format for the wall time SimpleDateFormat wallTimeFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z", ULocale.US); wallTimeFmt.setTimeZone(btz); long start = 1262304000000L; // 2010-01-01 0:00 UTC for (int i = 0; i < 5; i++) { // Up to 5 transitions TimeZoneTransition trans = btz.getPreviousTransition(start, false /* not including start time */); // Display the transition time and offset information long transTime = trans.getTime(); System.out.println(wallTimeFmt.format(new Date(transTime - 1)) + " -> " + wallTimeFmt.format(new Date(transTime))); System.out.println(" - Before (Offset/Save): " + trans.getFrom().getRawOffset() + "/" + trans.getFrom().getDSTSavings()); System.out.println(" - After (Offset/Save): " + trans.getTo().getRawOffset() + "/" + trans.getTo().getDSTSavings()); // Update start time for next transition start = transTime; }- Specified by:
getPreviousTransitionin classBasicTimeZone- Parameters:
base- The base time.inclusive- Whether the base time is inclusive or not.- Returns:
- A
Dateholding the last time zone transition time before the given base time, or null if no time zone transitions are available before the base time. - Status:
- Stable ICU 3.8.
-
getTimeZoneRules
[icu] Returns the array ofTimeZoneRulewhich represents the rule of this time zone object. The first element in the result array will be theInitialTimeZoneRuleinstance for the initial rule. The rest will be eitherAnnualTimeZoneRuleorTimeArrayTimeZoneRuleinstances representing transitions.- Specified by:
getTimeZoneRulesin classBasicTimeZone- Returns:
- The array of
TimeZoneRulewhich represents this time zone. - Status:
- Stable ICU 3.8.
-
isFrozen
-
freeze
-
cloneAsThawed
Provides for the clone operation. Any clone is initially unfrozen.- Specified by:
cloneAsThawedin interfaceFreezable<TimeZone>- Overrides:
cloneAsThawedin classTimeZone- Status:
- Stable ICU 49.
-