Java Reference
In-Depth Information
You can compare two
Calendar
objects by using
compareTo
since
Calendar
implements
Comparable
. If you prefer, you can use the
before
and
after
methods to compare the objects.
24.4.2. Time Zones
TimeZone
is an abstract class that encapsulates not only offset from
GMT
but also other offset issues, such as daylight saving time. As with oth-
er locale-sensitive classes, you can get the default
TimeZone
by invoking
the static method
geTDefault
. You can change the default time zone by
passing
setDefault
a new
TimeZone
object to useor
null
to reset to the
original default time zone. Time zones are understood by particular cal-
endar types, so you should ensure that the default calendar and time
zone are compatible.
Each time zone has a string identifier that is interpreted by the time
zone object and can be displayed to the user. These identifiers use a
long form consisting of a major and minor regional name, separated by
'
/
'. For example, the following are all valid time zone identifiers:
Amer-
ica/New_York
,
Australia/Brisbane
,
Africa/Timbuktu
. Many time zones have
a short form identifier often just a three letter acronymsome of which
are recognized by
TimeZone
for backward compatibility. You should en-
deavor to always use the long formafter all, while many people know
that
EST
stands for "Eastern Standard Time," that doesn't tell you for
which country.
TimeZone
also recognizes generic identifiers expressed as
the difference in time from
GMT
. For example,
GMT+10:00
and
GMT-4:00
are
both valid generic time zone identifiers. You can get an array of all the
identifiers available on your system from the static method
getAvail-
ableIDs
. If you want only those for a given offset from
GMT
, you can in-
voke
getAvailableIDs
with that offset. An offset might, for example, have
identifiers for both daylight saving and standard time zones.
You can find the identifier of a given
TimeZone
object from
getID
, and you
can set it with
setID
. Setting the identifier changes only the identifier on
the time zoneit does not change the offset or other values. You can get
the time zone for a given identifier by passing it to the static method
getTimeZone
.