Class VTimeZone
- All Implemented Interfaces:
Freezable<TimeZone>, Serializable, Cloneable
VTimeZone is a class implementing RFC2445 VTIMEZONE. You can create a
VTimeZone instance from a time zone ID supported by TimeZone. With the
VTimeZone instance created from the ID, you can write out the rule in RFC2445 VTIMEZONE
format. Also, you can create a VTimeZone instance from RFC2445 VTIMEZONE data
stream, which allows you to calculate time zone offset by the rules defined by the data.Note: The consumer of this class reading or writing VTIMEZONE data is responsible to decode or encode Non-ASCII text. Methods reading/writing VTIMEZONE data in this class do nothing with MIME encoding.
- See Also:
- Status:
- Stable ICU 3.8.
-
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
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. -
Method Summary
Modifier and TypeMethodDescriptionclone()Overrides clone.Provides for the clone operation.static VTimeZoneCreate aVTimeZoneinstance by RFC2445 VTIMEZONE data.static VTimeZoneCreate aVTimeZoneinstance by the time zone ID.freeze()Freezes the object.Gets the RFC2445 LAST-MODIFIED property value.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 milliseconds) Gets the time zone offset, for current date, modified in case of daylight savings.voidgetOffset(long date, boolean local, int[] offsets) Returns the time zone raw and GMT offset for the given moment in time.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.intGets unmodified offset, NOT modified in case of daylight savings.[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.getTZURL()Gets the RFC2445 TZURL property value.booleanhasEquivalentTransitions(TimeZone other, long start, long end) [icu] Checks if the time zone has equivalent transitions in the time range.booleanhasSameRules(TimeZone other) Returns true if this zone has the same rule and offset as another zone.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.voidsetLastModified(Date date) Sets the date used for RFC2445 LAST-MODIFIED property value.voidsetRawOffset(int offsetMillis) Sets the base time zone offset to GMT.voidSets the RFC2445 TZURL property value.booleanQueries if this time zone uses daylight savings time.voidWrites RFC2445 VTIMEZONE data for this time zonevoidWrites RFC2445 VTIMEZONE data applicable for dates after the specified start time.voidwriteSimple(Writer writer, long time) Writes RFC2445 VTIMEZONE data applicable near the specified date.Methods inherited from class BasicTimeZone
getLocalOptionValue, getSimpleTimeZoneRulesNear, 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.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, equals, forLocaleOrDefault, forULocaleOrDefault, getAvailableIDs, getAvailableIDs, getAvailableIDs, getAvailableIDs, getCanonicalID, getCanonicalID, getDefault, getDefaultTimeZoneType, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDSTSavings, getEquivalentID, getFrozenTimeZone, getIanaID, getID, getIDForWindowsID, getOffset, getRegion, getTimeZone, getTimeZone, getTZDataVersion, getWindowsID, hashCode, setDefault, setDefaultTimeZoneType, setICUDefault, setIDModifier and TypeMethodDescriptionstatic 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.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.intgetOffset(long date) Returns the offset of this time zone from UTC at the specified date.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.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.
-
Method Details
-
create
-
create
Create aVTimeZoneinstance by RFC2445 VTIMEZONE data.- Parameters:
reader- The Reader for VTIMEZONE data input stream- Returns:
- A
VTimeZoneinitialized by the VTIMEZONE data or null if failed to load the rule from the VTIMEZONE data. - Status:
- Stable ICU 3.8.
-
getOffset
public 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 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.milliseconds- the millis in day in standard local time.- Returns:
- the offset to add to GMT to get local time.
- Status:
- Stable ICU 3.8.
-
getOffset
public void getOffset(long date, boolean local, int[] offsets) Returns the time zone raw and GMT offset for the given moment in time. Upon return, local-millis = GMT-millis + rawOffset + dstOffset. All computations are performed in the proleptic Gregorian calendar. The default implementation in the TimeZone class delegates to the 8-argument getOffset().- Overrides:
getOffsetin classTimeZone- Parameters:
date- moment in time for which to return offsets, in units of milliseconds from January 1, 1970 0:00 GMT, either GMT time or local wall time, depending onlocal.local- if true,dateis local wall time; otherwise it is in GMT time.offsets- output parameter to receive the raw offset, that is, the offset not including DST adjustments, in offsets[0], and the DST offset, that is, the offset to be added torawOffsetto obtain the total offset between local and GMT time, in offsets[1]. If DST is not in effect, the DST offset is zero; otherwise it is a positive value, typically one hour.- Status:
- Stable ICU 3.8.
-
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.
-
getRawOffset
public int getRawOffset()Gets unmodified offset, NOT modified in case of daylight savings. This is the offset to add to UTC to get local time.- Specified by:
getRawOffsetin classTimeZone- Returns:
- the unmodified offset to add to UTC to get local time.
- Status:
- Stable ICU 3.8.
-
inDaylightTime
Queries if the given date is in daylight savings time in this time zone.- 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 3.8.
-
setRawOffset
public void setRawOffset(int offsetMillis) 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 given base time zone offset to GMT.- Status:
- Stable ICU 3.8.
-
useDaylightTime
public boolean useDaylightTime()Queries if this time zone uses daylight savings 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 3.8.
-
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.
-
hasSameRules
Returns true if this zone has the same rule and offset as another zone. That is, if this zone differs only in ID, if at all. Returns false if the other zone is null.- Overrides:
hasSameRulesin classTimeZone- Parameters:
other- theTimeZoneobject to be compared with- Returns:
- true if the other zone is not null and is the same as this one, with the possible exception of the ID
- Status:
- Stable ICU 3.8.
-
getTZURL
Gets the RFC2445 TZURL property value. When aVTimeZoneinstance was created from VTIMEZONE data, the value is set by the TZURL property value in the data. Otherwise, the initial value is null.- Returns:
- The RFC2445 TZURL property value
- Status:
- Stable ICU 3.8.
-
setTZURL
Sets the RFC2445 TZURL property value.- Parameters:
url- The TZURL property value.- Status:
- Stable ICU 3.8.
-
getLastModified
Gets the RFC2445 LAST-MODIFIED property value. When aVTimeZoneinstance was created from VTIMEZONE data, the value is set by the LAST-MODIFIED property value in the data. Otherwise, the initial value is null.- Returns:
- The Date represents the RFC2445 LAST-MODIFIED date.
- Status:
- Stable ICU 3.8.
-
setLastModified
Sets the date used for RFC2445 LAST-MODIFIED property value.- Parameters:
date- TheDateobject represents the date for RFC2445 LAST-MODIFIED property value.- Status:
- Stable ICU 3.8.
-
write
Writes RFC2445 VTIMEZONE data for this time zone- Parameters:
writer- AWriterused for the output- Throws:
IOException- If there were problems creating a buffered writer or writing to it.- Status:
- Stable ICU 3.8.
-
write
Writes RFC2445 VTIMEZONE data applicable for dates after the specified start time.- Parameters:
writer- TheWriterused for the outputstart- The start time- Throws:
IOException- If there were problems reading and writing to the writer.- Status:
- Stable ICU 3.8.
-
writeSimple
Writes RFC2445 VTIMEZONE data applicable near the specified date. Some common iCalendar implementations can only handle a single time zone property or a pair of standard and daylight time properties using BYDAY rule with day of week (such as BYDAY=1SUN). This method produce the VTIMEZONE data which can be handled these implementations. The rules produced by this method can be used only for calculating time zone offset around the specified date.- Parameters:
writer- TheWriterused for the outputtime- The date- Throws:
IOException- If there were problems reading or writing to the writer.- Status:
- Stable ICU 3.8.
-
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.
-
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); }- Overrides:
hasEquivalentTransitionsin classBasicTimeZone- Parameters:
other- 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.
-
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.
-
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]); }- Overrides:
getTimeZoneRulesin classBasicTimeZone- Parameters:
start- The start time (inclusive).- Returns:
- The array of
TimeZoneRulewhich represents this time zone since the start time. - Status:
- Stable ICU 3.8.
-
clone
-
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.
-