Java The Complete Reference, Seventh Edition

(Greg DeLong) #1

SimpleTimeZone


TheSimpleTimeZoneclass is a convenient subclass ofTimeZone. It implementsTimeZone’s
abstract methods and allows you to work with time zones for a Gregorian calendar. It also
computes daylight saving time.
SimpleTimeZonedefines four constructors. One is

SimpleTimeZone(inttimeDelta, StringtzName)

This constructor creates aSimpleTimeZoneobject. The offset relative to Greenwich mean
time (GMT) istimeDelta.The time zone is namedtzName.

514 Part II: The Java Library


Method Description
Object clone( ) Returns aTimeZone-specific version ofclone( ).
static String[ ] getAvailableIDs( ) Returns an array ofStringobjects representing the
names of all time zones.
static String[ ]
getAvailableIDs(inttimeDelta)

Returns an array ofStringobjects representing the
names of all time zones that aretimeDeltaoffset from
GMT.
static TimeZone getDefault( ) Returns aTimeZoneobject that represents the default
time zone used on the host computer.
String getID( ) Returns the name of the invokingTimeZoneobject.
abstract int getOffset(intera, intyear,
intmonth,
intdayOfMonth,
intdayOfWeek,
intmillisec)

Returns the offset that should be added to GMT to
compute local time. This value is adjusted for daylight
saving time. The parameters to the method represent
date and time components.

abstract int getRawOffset( ) Returns the raw offset that should be added to GMT
to compute local time. This value is not adjusted for
daylight saving time.
static TimeZone
getTimeZone(StringtzName)

Returns theTimeZoneobject for the time zone named
tzName.
abstract boolean inDaylightTime(Dated) Returnstrueif the date represented bydis in daylight
saving time in the invoking object. Other wise, it
returnsfalse.
static void setDefault(TimeZonetz) Sets the default time zone to be used on this host.tz
is a reference to theTimeZoneobject to be used.
void setID(StringtzName) Sets the name of the time zone (that is, its ID) to that
specified bytzName.
abstract void setRawOffset(intmillis) Sets the offset in milliseconds from GMT.
abstract boolean useDaylightTime( ) Returnstrueif the invoking object uses daylight saving
time. Other wise, it returnsfalse.

TABLE 18-5 Some of the Methods Defined byTimeZone
Free download pdf