| Method from java.util.TimeZone Detail: |
public Object clone() {
try {
TimeZone zone = (TimeZone) super.clone();
return zone;
} catch (CloneNotSupportedException e) {
return null;
}
}
Returns a new {@code TimeZone} with the same ID, {@code rawOffset} and daylight savings
time rules as this {@code TimeZone}. |
public static synchronized String[] getAvailableIDs() {
return com.ibm.icu.util.TimeZone.getAvailableIDs();
}
Gets the available time zone IDs. Any one of these IDs can be passed to
{@code get()} to create the corresponding {@code TimeZone} instance. |
public static synchronized String[] getAvailableIDs(int offset) {
String[] availableIDs = com.ibm.icu.util.TimeZone.getAvailableIDs();
int count = 0;
int length = availableIDs.length;
String[] all = new String[length];
for (int i = 0; i < length; i++) {
com.ibm.icu.util.TimeZone tz = com.ibm.icu.util.TimeZone
.getTimeZone(availableIDs[i]);
if (tz.getRawOffset() == offset) {
all[count++] = tz.getID();
}
}
String[] answer = new String[count];
System.arraycopy(all, 0, answer, 0, count);
return answer;
}
Gets the available time zone IDs which match the specified offset from
GMT. Any one of these IDs can be passed to {@code get()} to create the corresponding
{@code TimeZone} instance. |
public int getDSTSavings() {
if (useDaylightTime()) {
return 3600000;
}
return 0;
}
Gets the daylight savings offset in milliseconds for this {@code TimeZone}.
This implementation returns 3600000 (1 hour), or 0 if the time zone does
not observe daylight savings.
Subclasses may override to return daylight savings values other than 1
hour.
|
public static synchronized TimeZone getDefault() {
if (Default == null) {
setDefault(null);
}
return (TimeZone) Default.clone();
}
Gets the default time zone. |
public final String getDisplayName() {
return getDisplayName(false, LONG, Locale.getDefault());
}
Gets the LONG name for this {@code TimeZone} for the default {@code Locale} in standard
time. If the name is not available, the result is in the format
{@code GMT[+-]hh:mm}. |
public final String getDisplayName(Locale locale) {
return getDisplayName(false, LONG, locale);
}
Gets the LONG name for this {@code TimeZone} for the specified {@code Locale} in standard
time. If the name is not available, the result is in the format
{@code GMT[+-]hh:mm}. |
public final String getDisplayName(boolean daylightTime,
int style) {
return getDisplayName(daylightTime, style, Locale.getDefault());
}
Gets the specified style of name ({@code LONG} or {@code SHORT}) for this {@code TimeZone} for
the default {@code Locale} in either standard or daylight time as specified. If
the name is not available, the result is in the format {@code GMT[+-]hh:mm}. |
public String getDisplayName(boolean daylightTime,
int style,
Locale locale) {
if(icuTimeZone == null || !ID.equals(icuTimeZone.getID())){
icuTimeZone = com.ibm.icu.util.TimeZone.getTimeZone(ID);
}
return icuTimeZone.getDisplayName(
daylightTime, style, locale);
}
Gets the specified style of name ({@code LONG} or {@code SHORT}) for this {@code TimeZone} for
the specified {@code Locale} in either standard or daylight time as specified. If
the name is not available, the result is in the format {@code GMT[+-]hh:mm}. |
public String getID() {
return ID;
}
Gets the ID of this {@code TimeZone}. |
public int getOffset(long time) {
if (inDaylightTime(new Date(time))) {
return getRawOffset() + getDSTSavings();
}
return getRawOffset();
}
Gets the offset from GMT of this {@code TimeZone} for the specified date. The
offset includes daylight savings time if the specified date is within the
daylight savings time period. |
abstract public int getOffset(int era,
int year,
int month,
int day,
int dayOfWeek,
int time)
Gets the offset from GMT of this {@code TimeZone} for the specified date and
time. The offset includes daylight savings time if the specified date and
time are within the daylight savings time period. |
abstract public int getRawOffset()
Gets the offset for standard time from GMT for this {@code TimeZone}. |
public static synchronized TimeZone getTimeZone(String name) {
if (AvailableZones == null) {
initializeAvailable();
}
TimeZone zone = AvailableZones.get(name);
if(zone == null && isAvailableIDInICU(name)){
appendAvailableZones(name);
zone = AvailableZones.get(name);
}
if (zone == null) {
if (name.startsWith("GMT") && name.length() > 3) {
char sign = name.charAt(3);
if (sign == '+' || sign == '-') {
int[] position = new int[1];
String formattedName = formatTimeZoneName(name, 4);
int hour = parseNumber(formattedName, 4, position);
if (hour < 0 || hour > 23) {
return (TimeZone) GMT.clone();
}
int index = position[0];
if (index != -1) {
int raw = hour * 3600000;
if (index < formattedName.length()
&& formattedName.charAt(index) == ':') {
int minute = parseNumber(formattedName, index + 1,
position);
if (position[0] == -1 || minute < 0 || minute > 59) {
return (TimeZone) GMT.clone();
}
raw += minute * 60000;
} else if (hour >= 30 || index > 6) {
raw = (hour / 100 * 3600000) + (hour % 100 * 60000);
}
if (sign == '-') {
raw = -raw;
}
return new SimpleTimeZone(raw, formattedName);
}
}
}
zone = GMT;
}
return (TimeZone) zone.clone();
}
Gets the {@code TimeZone} with the specified ID. |
public boolean hasSameRules(TimeZone zone) {
if (zone == null) {
return false;
}
return getRawOffset() == zone.getRawOffset();
}
Returns whether the specified {@code TimeZone} has the same raw offset as this
{@code TimeZone}. |
abstract public boolean inDaylightTime(Date time)
Returns whether the specified {@code Date} is in the daylight savings time period for
this {@code TimeZone}. |
public static synchronized void setDefault(TimeZone timezone) {
if (timezone != null) {
setICUDefaultTimeZone(timezone);
Default = timezone;
return;
}
String zone = AccessController.doPrivileged(new PriviAction< String >(
"user.timezone"));
// sometimes DRLVM incorrectly adds "\n" to the end of timezone ID
if (zone != null && zone.contains("\n")) {
zone = zone.substring(0, zone.indexOf("\n"));
}
// if property user.timezone is not set, we call the native method
// getCustomTimeZone
if (zone == null || zone.length() == 0) {
int[] tzinfo = new int[10];
boolean[] isCustomTimeZone = new boolean[1];
String zoneId = getCustomTimeZone(tzinfo, isCustomTimeZone);
// if returned TimeZone is a user customized TimeZone
if (isCustomTimeZone[0]) {
// build a new SimpleTimeZone
switch (tzinfo[1]) {
case 0:
// does not observe DST
Default = new SimpleTimeZone(tzinfo[0], zoneId);
break;
default:
// observes DST
Default = new SimpleTimeZone(tzinfo[0], zoneId, tzinfo[5],
tzinfo[4], tzinfo[3], tzinfo[2], tzinfo[9],
tzinfo[8], tzinfo[7], tzinfo[6], tzinfo[1]);
}
} else {
// get TimeZone
Default = getTimeZone(zoneId);
}
} else {
// if property user.timezone is set in command line (with -D option)
Default = getTimeZone(zone);
}
setICUDefaultTimeZone(Default);
}
Sets the default time zone. If passed {@code null}, then the next
time #getDefault is called, the default time zone will be
determined. This behavior is slightly different than the canonical
description of this method, but it follows the spirit of it. |
public void setID(String name) {
if (name == null) {
throw new NullPointerException();
}
ID = name;
}
Sets the ID of this {@code TimeZone}. |
abstract public void setRawOffset(int offset)
Sets the offset for standard time from GMT for this {@code TimeZone}. |
abstract public boolean useDaylightTime()
Returns whether this {@code TimeZone} has a daylight savings time period. |