Methods Summary |
---|
public java.lang.Object | clone()Creates a copy of this TimeZone .
try {
TimeZone other = (TimeZone) super.clone();
other.ID = ID;
return other;
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
|
public static synchronized java.lang.String[] | getAvailableIDs(int rawOffset)Gets the available IDs according to the given time zone offset.
return ZoneInfo.getAvailableIDs(rawOffset);
|
public static synchronized java.lang.String[] | getAvailableIDs()Gets all the available IDs supported.
return ZoneInfo.getAvailableIDs();
|
public int | getDSTSavings()Returns the amount of time to be added to local standard time
to get local wall clock time.
The default implementation always returns 3600000 milliseconds
(i.e., one hour) if this time zone observes Daylight Saving
Time. Otherwise, 0 (zero) is returned.
If an underlying TimeZone implementation subclass supports
historical Daylight Saving Time changes, this method returns
the known latest daylight saving value.
if (useDaylightTime()) {
return 3600000;
}
return 0;
|
public static synchronized java.util.TimeZone | getDefault()Gets the default TimeZone for this host.
The source of the default TimeZone
may vary with implementation.
TimeZone defaultZone = (TimeZone) defaultZoneTL.get();
if (defaultZone == null) {
setDefaultZone();
defaultZone = (TimeZone) defaultZoneTL.get();
}
return (TimeZone) defaultZone.clone();
|
static synchronized java.util.TimeZone | getDefaultRef()Returns the reference to the default TimeZone object. This
method doesn't create a clone.
TimeZone defaultZone = (TimeZone) defaultZoneTL.get();
if (defaultZone == null) {
setDefaultZone();
defaultZone = (TimeZone) defaultZoneTL.get();
}
return defaultZone;
|
public final java.lang.String | getDisplayName(java.util.Locale locale)Returns a name of this time zone suitable for presentation to the user
in the specified locale.
This method returns the long name, not including daylight savings.
If the display name is not available for the locale,
then this method returns a string in the
normalized custom ID format.
return getDisplayName(false, LONG, locale);
|
public final java.lang.String | getDisplayName(boolean daylight, int style)Returns a name of this time zone suitable for presentation to the user
in the default locale.
If the display name is not available for the locale, then this
method returns a string in the
normalized custom ID format.
return getDisplayName(daylight, style, Locale.getDefault());
|
public java.lang.String | getDisplayName(boolean daylight, int style, java.util.Locale locale)Returns a name of this time zone suitable for presentation to the user
in the specified locale.
If the display name is not available for the locale,
then this method returns a string in the
normalized custom ID format.
if (style != SHORT && style != LONG) {
throw new IllegalArgumentException("Illegal style: " + style);
}
String id = getID();
String[] names = getDisplayNames(id, locale);
if (names == null) {
if (id.startsWith("GMT")) {
char sign = id.charAt(3);
if (sign == '+" || sign == '-") {
return id;
}
}
int offset = getRawOffset();
if (daylight) {
offset += getDSTSavings();
}
return ZoneInfoFile.toCustomID(offset);
}
int index = daylight && useDaylightTime() ? 3 : 1;
if (style == SHORT) {
index++;
}
return names[index];
|
public final java.lang.String | getDisplayName()Returns a name of this time zone suitable for presentation to the user
in the default locale.
This method returns the long name, not including daylight savings.
If the display name is not available for the locale,
then this method returns a string in the
normalized custom ID format.
return getDisplayName(false, LONG, Locale.getDefault());
|
private static final java.lang.String[] | getDisplayNames(java.lang.String id, java.util.Locale locale)
synchronized (TimeZone.class) {
if (displayNames == null) {
displayNames = new HashMap<String, SoftReference>();
}
}
synchronized (displayNames) {
String[] names;
SoftReference ref = displayNames.get(id);
Map<Locale, String[]> perLocale;
if (ref != null) {
perLocale = (Map<Locale, String[]>) ref.get();
if (perLocale != null) {
names = perLocale.get(locale);
if (names != null) {
return names;
}
names = retrieveDisplayNames(id, locale);
if (names != null) {
perLocale.put(locale, names);
}
return names;
}
}
names = retrieveDisplayNames(id, locale);
if (names != null) {
perLocale = new HashMap<Locale, String[]>();
perLocale.put(locale, names);
ref = new SoftReference(perLocale);
displayNames.put(id, ref);
}
return names;
}
|
public java.lang.String | getID()Gets the ID of this time zone.
return ID;
|
public abstract 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.
This method returns a historically correct offset if an
underlying TimeZone implementation subclass
supports historical Daylight Saving Time schedule and GMT
offset changes.
|
public int | getOffset(long date)Returns the offset of this time zone from UTC at the specified
date. If Daylight Saving Time is in effect at the specified
date, the offset value is adjusted with the amount of daylight
saving.
This method returns a historically correct offset value if an
underlying TimeZone implementation subclass supports historical
Daylight Saving Time schedule and GMT offset changes.
if (inDaylightTime(new Date(date))) {
return getRawOffset() + getDSTSavings();
}
return getRawOffset();
|
int | getOffsets(long date, int[] offsets)Gets the raw GMT offset and the amount of daylight saving of this
time zone at the given time.
int rawoffset = getRawOffset();
int dstoffset = 0;
if (inDaylightTime(new Date(date))) {
dstoffset = getDSTSavings();
}
if (offsets != null) {
offsets[0] = rawoffset;
offsets[1] = dstoffset;
}
return rawoffset + dstoffset;
|
public abstract int | getRawOffset()Returns the amount of time in milliseconds to add to UTC to get
standard time in this time zone. Because this value is not
affected by daylight saving time, it is called raw
offset.
If an underlying TimeZone implementation subclass
supports historical GMT offset changes, the method returns the
raw offset value of the current date. In Honolulu, for example,
its raw offset changed from GMT-10:30 to GMT-10:00 in 1947, and
this method always returns -36000000 milliseconds (i.e., -10
hours).
|
private static native java.lang.String | getSystemGMTOffsetID()Gets the custom time zone ID based on the GMT offset of the
platform. (e.g., "GMT+08:00")
|
private static native java.lang.String | getSystemTimeZoneID(java.lang.String javaHome, java.lang.String country)Gets the platform defined TimeZone ID.
|
public static synchronized java.util.TimeZone | getTimeZone(java.lang.String ID)Gets the TimeZone for the given ID.
return getTimeZone(ID, true);
|
private static java.util.TimeZone | getTimeZone(java.lang.String ID, boolean fallback)
TimeZone tz = ZoneInfo.getTimeZone(ID);
if (tz == null) {
tz = parseCustomTimeZone(ID);
if (tz == null && fallback) {
tz = new ZoneInfo(GMT_ID, 0);
}
}
return tz;
|
public boolean | hasSameRules(java.util.TimeZone other)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.
return other != null && getRawOffset() == other.getRawOffset() &&
useDaylightTime() == other.useDaylightTime();
|
public abstract boolean | inDaylightTime(java.util.Date date)Queries if the given date is in daylight savings time in
this time zone.
|
private static final java.util.TimeZone | parseCustomTimeZone(java.lang.String id)Parses a custom time zone identifier and returns a corresponding zone.
This method doesn't support the RFC 822 time zone format. (e.g., +hhmm)
int length;
// Error if the length of id isn't long enough or id doesn't
// start with "GMT".
if ((length = id.length()) < (GMT_ID_LENGTH + 2) ||
id.indexOf(GMT_ID) != 0) {
return null;
}
ZoneInfo zi;
// First, we try to find it in the cache with the given
// id. Even the id is not normalized, the returned ZoneInfo
// should have its normalized id.
zi = ZoneInfoFile.getZoneInfo(id);
if (zi != null) {
return zi;
}
int index = GMT_ID_LENGTH;
boolean negative = false;
char c = id.charAt(index++);
if (c == '-") {
negative = true;
} else if (c != '+") {
return null;
}
int hours = 0;
int num = 0;
int countDelim = 0;
int len = 0;
while (index < length) {
c = id.charAt(index++);
if (c == ':") {
if (countDelim > 0) {
return null;
}
if (len > 2) {
return null;
}
hours = num;
countDelim++;
num = 0;
len = 0;
continue;
}
if (c < '0" || c > '9") {
return null;
}
num = num * 10 + (c - '0");
len++;
}
if (index != length) {
return null;
}
if (countDelim == 0) {
if (len <= 2) {
hours = num;
num = 0;
} else {
hours = num / 100;
num %= 100;
}
} else {
if (len != 2) {
return null;
}
}
if (hours > 23 || num > 59) {
return null;
}
int gmtOffset = (hours * 60 + num) * 60 * 1000;
if (gmtOffset == 0) {
zi = ZoneInfoFile.getZoneInfo(GMT_ID);
if (negative) {
zi.setID("GMT-00:00");
} else {
zi.setID("GMT+00:00");
}
} else {
zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset);
}
return zi;
|
private static final java.lang.String[] | retrieveDisplayNames(java.lang.String id, java.util.Locale locale)
String[][] tznames = new DateFormatSymbols(locale).getZoneStrings();
for (int i = 0; i < tznames.length; i++) {
String[] names = tznames[i];
if (id.equals(names[0])) {
return names;
}
}
return null;
|
public static synchronized void | setDefault(java.util.TimeZone zone)Sets the TimeZone that is
returned by the getDefault method. If zone
is null, reset the default to the value it had originally when the
VM first started.
defaultZoneTL.set(zone);
|
private static void | setDefaultZone()
TimeZone tz = null;
// get the time zone ID from the system properties
String zoneID = (String) AccessController.doPrivileged(
new GetPropertyAction("user.timezone"));
// if the time zone ID is not set (yet), perform the
// platform to Java time zone ID mapping.
if (zoneID == null || zoneID.equals("")) {
String country = (String) AccessController.doPrivileged(
new GetPropertyAction("user.country"));
String javaHome = (String) AccessController.doPrivileged(
new GetPropertyAction("java.home"));
try {
zoneID = getSystemTimeZoneID(javaHome, country);
if (zoneID == null) {
zoneID = GMT_ID;
}
} catch (NullPointerException e) {
zoneID = GMT_ID;
}
}
// Get the time zone for zoneID. But not fall back to
// "GMT" here.
tz = getTimeZone(zoneID, false);
if (tz == null) {
// If the given zone ID is unknown in Java, try to
// get the GMT-offset-based time zone ID,
// a.k.a. custom time zone ID (e.g., "GMT-08:00").
String gmtOffsetID = getSystemGMTOffsetID();
if (gmtOffsetID != null) {
zoneID = gmtOffsetID;
}
tz = getTimeZone(zoneID, true);
}
assert tz != null;
final String id = zoneID;
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
System.setProperty("user.timezone", id);
return null;
}
});
defaultZoneTL.set(tz);
|
public void | setID(java.lang.String ID)Sets the time zone ID. This does not change any other data in
the time zone object.
if (ID == null) {
throw new NullPointerException();
}
this.ID = ID;
|
public abstract void | setRawOffset(int offsetMillis)Sets the base time zone offset to GMT.
This is the offset to add to UTC to get local time.
If an underlying TimeZone implementation subclass
supports historical GMT offset changes, the specified GMT
offset is set as the latest GMT offset and the difference from
the known latest GMT offset value is used to adjust all
historical GMT offset values.
|
public abstract boolean | useDaylightTime()Queries if this time zone uses daylight savings time.
If an underlying TimeZone implementation subclass
supports historical Daylight Saving Time schedule changes, the
method refers to the latest Daylight Saving Time schedule
information.
|