public class VTimeZone extends BasicTimeZone
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.TimeZone.SystemTimeZoneTypeFORMER_LATTER_MASK, LOCAL_DST, LOCAL_FORMER, LOCAL_LATTER, LOCAL_STD, STD_DST_MASKGENERIC_LOCATION, GMT_ZONE, LONG, LONG_GENERIC, LONG_GMT, SHORT, SHORT_COMMONLY_USED, SHORT_GENERIC, SHORT_GMT, TIMEZONE_ICU, TIMEZONE_JDK, UNKNOWN_ZONE, UNKNOWN_ZONE_ID| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
clone()
Overrides clone.
|
TimeZone |
cloneAsThawed()
Provides for the clone operation.
|
static VTimeZone |
create(java.io.Reader reader)
Create a
VTimeZone instance by RFC2445 VTIMEZONE data. |
static VTimeZone |
create(java.lang.String tzid)
Create a
VTimeZone instance by the time zone ID. |
TimeZone |
freeze()
Freezes the object.
|
java.util.Date |
getLastModified()
Gets the RFC2445 LAST-MODIFIED property value.
|
TimeZoneTransition |
getNextTransition(long base,
boolean inclusive)
[icu] Returns the first time zone transition after the base time.
|
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.
|
void |
getOffset(long date,
boolean local,
int[] offsets)
Returns the time zone raw and GMT offset for the given moment
in time.
|
void |
getOffsetFromLocal(long date,
int nonExistingTimeOpt,
int duplicatedTimeOpt,
int[] offsets)
Deprecated.
This API is ICU internal only.
|
TimeZoneTransition |
getPreviousTransition(long base,
boolean inclusive)
[icu] Returns the last time zone transition before the base time.
|
int |
getRawOffset()
Gets unmodified offset, NOT modified in case of daylight savings.
|
TimeZoneRule[] |
getTimeZoneRules()
[icu] Returns the array of
TimeZoneRule which represents the rule
of this time zone object. |
TimeZoneRule[] |
getTimeZoneRules(long start)
[icu] Returns the array of
TimeZoneRule which represents the rule
of this time zone object since the specified start time. |
java.lang.String |
getTZURL()
Gets the RFC2445 TZURL property value.
|
boolean |
hasEquivalentTransitions(TimeZone other,
long start,
long end)
[icu] Checks if the time zone has equivalent transitions in the time range.
|
boolean |
hasSameRules(TimeZone other)
Returns true if this zone has the same rule and offset as another zone.
|
boolean |
inDaylightTime(java.util.Date date)
Queries if the given date is in daylight savings time in
this time zone.
|
boolean |
isFrozen()
Determines whether the object has been frozen or not.
|
boolean |
observesDaylightTime()
Queries if this time zone is in daylight saving time or will observe
daylight saving time at any future time.
|
void |
setLastModified(java.util.Date date)
Sets the date used for RFC2445 LAST-MODIFIED property value.
|
void |
setRawOffset(int offsetMillis)
Sets the base time zone offset to GMT.
|
void |
setTZURL(java.lang.String url)
Sets the RFC2445 TZURL property value.
|
boolean |
useDaylightTime()
Queries if this time zone uses daylight savings time.
|
void |
write(java.io.Writer writer)
Writes RFC2445 VTIMEZONE data for this time zone
|
void |
write(java.io.Writer writer,
long start)
Writes RFC2445 VTIMEZONE data applicable for dates after
the specified start time.
|
void |
writeSimple(java.io.Writer writer,
long time)
Writes RFC2445 VTIMEZONE data applicable near the specified date.
|
getSimpleTimeZoneRulesNear, hasEquivalentTransitionscountEquivalentIDs, equals, getAvailableIDs, getAvailableIDs, getAvailableIDs, getAvailableIDs, getCanonicalID, getCanonicalID, getDefault, getDefaultTimeZoneType, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getDSTSavings, getEquivalentID, getFrozenTimeZone, getID, getIDForWindowsID, getOffset, getRegion, getTimeZone, getTimeZone, getTZDataVersion, getWindowsID, hashCode, setDefault, setDefaultTimeZoneType, setICUDefault, setIDpublic static VTimeZone create(java.lang.String tzid)
VTimeZone instance by the time zone ID.tzid - The time zone ID, such as America/New_YorkVTimeZone initialized by the time zone ID, or null
when the ID is unknown.public static VTimeZone create(java.io.Reader reader)
VTimeZone instance by RFC2445 VTIMEZONE data.reader - The Reader for VTIMEZONE data input streamVTimeZone initialized by the VTIMEZONE data or
null if failed to load the rule from the VTIMEZONE data.public int getOffset(int era,
int year,
int month,
int day,
int dayOfWeek,
int milliseconds)
getOffset in class TimeZoneera - 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.public void getOffset(long date,
boolean local,
int[] offsets)
getOffset in class TimeZonedate - 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 on `local'.local - if true, `date' is 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 to
`rawOffset' to 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.@Deprecated
public void getOffsetFromLocal(long date,
int nonExistingTimeOpt,
int duplicatedTimeOpt,
int[] offsets)
getOffsetFromLocal in class BasicTimeZonepublic int getRawOffset()
getRawOffset in class TimeZonepublic boolean inDaylightTime(java.util.Date date)
inDaylightTime in class TimeZonedate - the given Date.public void setRawOffset(int offsetMillis)
setRawOffset in class TimeZoneoffsetMillis - the given base time zone offset to GMT.public boolean useDaylightTime()
useDaylightTime in class TimeZoneNote: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 false for such case.
The default implementation of this method returns true
when the time zone uses daylight savings time in the current
(Gregorian) calendar year.
public boolean observesDaylightTime()
The default implementation in this class returns true if TimeZone.useDaylightTime()
or inDaylightTime(new Date()) returns true.
Note: This method was added for TimeZone compatibility
support. The TimeZone.useDaylightTime() method only checks the last known
rule(s), therefore it may return false even the zone observes daylight saving time currently.
TimeZone added observesDaylightTime() 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 return
false if daylight saving time is currently used.
ICU's TimeZone subclass implementations override this method to support the same behavior
with TimeZone.observesDaylightTime(). Unlike TimeZone.useDaylightTime(),
the implementation does not take past daylight saving time into account, so
that this method may return false even when TimeZone.useDaylightTime() returns
true.
observesDaylightTime in class TimeZonetrue if this time zone is in daylight saving time or will observe
daylight saving time at any future time.TimeZone.useDaylightTime()public boolean hasSameRules(TimeZone other)
hasSameRules in class TimeZoneother - the TimeZone object to be compared withpublic java.lang.String getTZURL()
VTimeZone instance was created from
VTIMEZONE data, the value is set by the TZURL property value in the data. Otherwise,
the initial value is null.public void setTZURL(java.lang.String url)
url - The TZURL property value.public java.util.Date getLastModified()
VTimeZone instance was created
from VTIMEZONE data, the value is set by the LAST-MODIFIED property value in the data.
Otherwise, the initial value is null.public void setLastModified(java.util.Date date)
date - The Date object represents the date for RFC2445 LAST-MODIFIED property value.public void write(java.io.Writer writer)
throws java.io.IOException
writer - A Writer used for the outputjava.io.IOException - If there were problems creating a buffered writer or writing to it.public void write(java.io.Writer writer,
long start)
throws java.io.IOException
writer - The Writer used for the outputstart - The start timejava.io.IOException - If there were problems reading and writing to the writer.public void writeSimple(java.io.Writer writer,
long time)
throws java.io.IOException
writer - The Writer used for the outputtime - The datejava.io.IOException - If there were problems reading or writing to the writer.public TimeZoneTransition getNextTransition(long base, boolean inclusive)
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; }
getNextTransition in class BasicTimeZonebase - The base time.inclusive - Whether the base time is inclusive or not.Date holding the first time zone transition time
after the given base time, or null if no time zone transitions
are available after the base time.public TimeZoneTransition getPreviousTransition(long base, boolean inclusive)
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; }
getPreviousTransition in class BasicTimeZonebase - The base time.inclusive - Whether the base time is inclusive or not.Date holding the last time zone transition time
before the given base time, or null if no time zone transitions
are available before the base time.public boolean hasEquivalentTransitions(TimeZone other, long start, long end)
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); }
hasEquivalentTransitions in class BasicTimeZoneother - The instance of TimeZonestart - The start time of the evaluated time range (inclusive)end - The end time of the evaluated time range (inclusive)BasicTimeZone, this method
returns false.public TimeZoneRule[] getTimeZoneRules()
TimeZoneRule which represents the rule
of this time zone object. The first element in the result array will
be the InitialTimeZoneRule instance for the initial rule.
The rest will be either AnnualTimeZoneRule or
TimeArrayTimeZoneRule instances representing transitions.getTimeZoneRules in class BasicTimeZoneTimeZoneRule which represents this
time zone.public TimeZoneRule[] getTimeZoneRules(long start)
TimeZoneRule which represents the rule
of this time zone object since the specified start time. The first
element in the result array will be the InitialTimeZoneRule
instance for the initial rule. The rest will be either
AnnualTimeZoneRule or TimeArrayTimeZoneRule
instances 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]); }
getTimeZoneRules in class BasicTimeZonestart - The start time (inclusive).TimeZoneRule which represents this
time zone since the start time.public java.lang.Object clone()
public boolean isFrozen()
public TimeZone freeze()
public TimeZone cloneAsThawed()
cloneAsThawed in interface Freezable<TimeZone>cloneAsThawed in class TimeZoneCopyright © 2016 Unicode, Inc. and others.