Class BasicTimeZone
java.lang.Object
com.ibm.icu.util.TimeZone
com.ibm.icu.util.BasicTimeZone
- All Implemented Interfaces:
Freezable<TimeZone>, Serializable, Cloneable
- Direct Known Subclasses:
RuleBasedTimeZone, SimpleTimeZone, VTimeZone
Methods, fields, and other functionality specific to ICU are labeled '[icu]'. BasicTimeZone extends
TimeZone with additional methods to access time
zone transitions and rules. All ICU TimeZone concrete subclasses extend this class.
APIs added to java.util.TimeZone by BasicTimeZone are annotated with
'[icu]'.- See Also:
- Status:
- Stable ICU 3.8.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumMethods, fields, and other functionality specific to ICU are labeled '[icu]'. Options used bygetOffsetFromLocal(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 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
ConstructorsModifierConstructorDescriptionprotectedProtected no arg constructor.protectedBasicTimeZone(String ID) Deprecated.This API is ICU internal only. -
Method Summary
Modifier and TypeMethodDescriptionprotected static intDeprecated.This API is ICU internal only.abstract TimeZoneTransitiongetNextTransition(long base, boolean inclusive) [icu] Returns the first time zone transition after the base time.voidgetOffsetFromLocal(long date, BasicTimeZone.LocalOption nonExistingTimeOpt, BasicTimeZone.LocalOption duplicatedTimeOpt, int[] offsets) [icu] Returns time zone offsets from local wall time.abstract TimeZoneTransitiongetPreviousTransition(long base, boolean inclusive) [icu] Returns the last time zone transition before the base time.getSimpleTimeZoneRulesNear(long date) [icu] Returns the array ofTimeZoneRulewhich represents the rule of this time zone object near the specified date.abstract TimeZoneRule[][icu] Returns the array ofTimeZoneRulewhich represents the rule of this time zone object.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
clone, cloneAsThawed, countEquivalentIDs, equals, forLocaleOrDefault, forULocaleOrDefault, freeze, getAvailableIDs, getAvailableIDs, getAvailableIDs, getAvailableIDs, getCanonicalID, getCanonicalID, getDefault, getDefaultTimeZoneType, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDSTSavings, getEquivalentID, getFrozenTimeZone, getIanaID, getID, getIDForWindowsID, getOffset, getOffset, getOffset, getRawOffset, getRegion, getTimeZone, getTimeZone, getTZDataVersion, getWindowsID, hashCode, hasSameRules, inDaylightTime, isFrozen, observesDaylightTime, setDefault, setDefaultTimeZoneType, setICUDefault, setID, setRawOffset, useDaylightTimeModifier and TypeMethodDescriptionclone()Overrides clone.Provides for the clone operation.static int[icu] Returns the number of IDs in the equivalency group that includes the given ID.booleanOverrides equals.static TimeZoneforLocaleOrDefault(Locale locale) Deprecated.This API is ICU internal only.static TimeZoneforULocaleOrDefault(ULocale locale) Deprecated.This API is ICU internal only.freeze()Freezes the object.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.intReturns the amount of time to be added to local standard time to get local wall clock time.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.abstract 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.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.abstract intGets unmodified offset, NOT modified in case of daylight savings.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.inthashCode()Overrides hashCode.booleanhasSameRules(TimeZone other) Returns true if this zone has the same rule and offset as another zone.abstract booleaninDaylightTime(Date date) Queries if the given date is in daylight savings time in this time zone.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.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.voidSets the time zone ID.abstract voidsetRawOffset(int offsetMillis) Sets the base time zone offset to GMT.abstract booleanQueries if this time zone uses daylight savings time.
-
Field Details
-
LOCAL_STD
Deprecated.This API is ICU internal only.The time type option for standard time used by internal implementation.- See Also:
- Status:
- Internal. This API is ICU internal only.
-
LOCAL_DST
Deprecated.This API is ICU internal only.The time type option for daylight saving time used internally.- See Also:
- Status:
- Internal. This API is ICU internal only.
-
LOCAL_FORMER
Deprecated.This API is ICU internal only.The option designate former time used by internal implementation.- See Also:
- Status:
- Internal. This API is ICU internal only.
-
LOCAL_LATTER
Deprecated.This API is ICU internal only.The option designate latter time used by internal implementation.- See Also:
- Status:
- Internal. This API is ICU internal only.
-
STD_DST_MASK
Deprecated.This API is ICU internal only.The bit mask for the time type option used by internal implementation.- See Also:
- Status:
- Internal. This API is ICU internal only.
-
FORMER_LATTER_MASK
Deprecated.This API is ICU internal only.The bit mask for the former/latter option used by internal implementation.- See Also:
- Status:
- Internal. This API is ICU internal only.
-
-
Constructor Details
-
BasicTimeZone
protected BasicTimeZone()Protected no arg constructor.- Status:
- Stable ICU 3.8.
-
BasicTimeZone
Deprecated.This API is ICU internal only.Constructing a BasicTimeZone with the given time zone ID.- Parameters:
ID- the time zone ID.- Status:
- Internal. This API is ICU internal only.
-
-
Method Details
-
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; }- 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; }- 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.
-
hasEquivalentTransitions
[icu] Checks if the time zone has equivalent transitions in the time range. This method returns true when all of transition times, from/to standard offsets and DST savings used by this time zone match the other in the time range.Example code:
System.out.println("### Compare America/New_York and America/Detroit since year 1970"); // A TimeZone instance created by getTimeZone with TIMEZONE_ICU is always a BasicTimeZone BasicTimeZone tzNewYork = (BasicTimeZone)TimeZone.getTimeZone("America/New_York", TimeZone.TIMEZONE_ICU); BasicTimeZone tzDetroit = (BasicTimeZone)TimeZone.getTimeZone("America/Detroit", TimeZone.TIMEZONE_ICU); GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("Etc/GMT")); // Compare these time zones every 10 years since year 1970 up to year 2009 for (int startYear = 1970; startYear <= 2000; startYear += 10) { long start, end; cal.set(startYear, Calendar.JANUARY, 1, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); start = cal.getTimeInMillis(); // Set the end time to the end of startYear + 9 int endYear = startYear + 9; cal.set(endYear + 1, Calendar.JANUARY, 1, 0, 0, 0); end = cal.getTimeInMillis() - 1; // Check if these two zones have equivalent time zone transitions for the given time range boolean isEquivalent = tzNewYork.hasEquivalentTransitions(tzDetroit, start, end); System.out.println(startYear + "-" + endYear + ": " + isEquivalent); }- Parameters:
tz- The instance ofTimeZonestart- The start time of the evaluated time range (inclusive)end- The end time of the evaluated time range (inclusive)- Returns:
- true if the other time zone has the equivalent transitions in the time range. When tz
is not a
BasicTimeZone, this method returns false. - Status:
- Stable ICU 3.8.
-
hasEquivalentTransitions
[icu] Checks if the time zone has equivalent transitions in the time range. This method returns true when all of transition times, from/to standard offsets and DST savings used by this time zone match the other in the time range.- Parameters:
tz- The instance ofTimeZonestart- The start time of the evaluated time range (inclusive)end- The end time of the evaluated time range (inclusive)ignoreDstAmount- When true, any transitions with only daylight saving amount changes will be ignored, except either of them is zero. For example, a transition from rawoffset 3:00/dstsavings 1:00 to rawoffset 2:00/dstsavings 2:00 is excluded from the comparison, but a transition from rawoffset 2:00/dstsavings 1:00 to rawoffset 3:00/dstsavings 0:00 is included.- Returns:
- true if the other time zone has the equivalent transitions in the time range. When tz
is not a
BasicTimeZone, this method returns false. - 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.- Returns:
- The array of
TimeZoneRulewhich represents this time zone. - Status:
- Stable ICU 3.8.
-
getTimeZoneRules
[icu] Returns the array ofTimeZoneRulewhich represents the rule of this time zone object since the specified start time. The first element in the result array will be theInitialTimeZoneRuleinstance for the initial rule. The rest will be eitherAnnualTimeZoneRuleorTimeArrayTimeZoneRuleinstances representing transitions.Example code:
System.out.println("### Extracts time zone rules used by America/Los_Angeles since year 2005"); // A TimeZone instance created by getTimeZone with TIMEZONE_ICU is always a BasicTimeZone BasicTimeZone btz = (BasicTimeZone)TimeZone.getTimeZone("America/Los_Angeles", TimeZone.TIMEZONE_ICU); long since = 1104537600000L; // 2005-01-01 0:00 UTC TimeZoneRule[] rules = btz.getTimeZoneRules(since); System.out.println("Rule(initial): " + rules[0]); for (int i = 1; i < rules.length; i++) { System.out.println("Rule: " + rules[i]); }- Parameters:
start- The start time (inclusive).- Returns:
- The array of
TimeZoneRulewhich represents this time zone since the start time. - Status:
- Stable ICU 3.8.
-
getSimpleTimeZoneRulesNear
[icu] Returns the array ofTimeZoneRulewhich represents the rule of this time zone object near the specified date. Some applications are not capable to handle historic time zone rule changes. Also some applications can only handle certain type of rule definitions. This method returns either a singleInitialTimeZoneRuleif this time zone does not have any daylight saving time within 1 year from the specified time, or a pair ofAnnualTimeZoneRulewhose rule type isDateTimeRule.DOWfor date andDateTimeRule.WALL_TIMEfor time with a singleInitialTimeZoneRulerepresenting the initial time, when this time zone observes daylight saving time near the specified date. Thus, the result may be only valid for dates around the specified date.- Parameters:
date- The date to be used forTimeZoneRuleextraction.- Returns:
- The array of
TimeZoneRule, either a singleInitialTimeZoneRuleobject, or a pair ofAnnualTimeZoneRulewith a singleInitialTimeZoneRule. The first element in the array is always aInitialTimeZoneRule. - Status:
- Stable ICU 3.8.
-
getLocalOptionValue
Deprecated.This API is ICU internal only.GetBasicTimeZone.LocalOption's internal flag value. This is used by ICU internal implementation only.- Parameters:
locOpt- A LocalOption- Returns:
- LocalOption's internal flag value.
- 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.- Status:
- Stable ICU 69.
-