Name
Calendar
Synopsis
Calendar is an abstract base class for platform-dependent
classes that convert between date and time offsets. Since the rules for
converting between an absolute UTC time and a date may depend on local
conventions, application code does not directly instantiate a subclass of
Calendar. Instead, it uses one of the static
getInstance() methods, which returns an object that can
handle dates using rules appropriate to the device’s default locale.
This arrangement allows an application running in a device in a western
locale to obtain a Calendar that uses the rules of the
Gregorian calendar, while allowing the same application to work with other
calendars (such as Japanese Gregorian) in other locales.
The proper conversion of a point in time measured in UTC depends on the time
zone in which a device is being used. The Calendar object
returned by the zero-argument variant of getInstance()
performs the proper conversions for the default time zone of the device it
is running on. To create a Calendar for a different time
zone, obtain a TimeZone object for that time zone and
use the variant of getInstance() that accepts a
TimeZone argument. Alternatively, any
Calendar offset can be set to work in a different time
zone by calling the setTimeZone() method.
The date and time associated with a Calendar object can
be set from a Date object using the
setTime() method, or to an absolute time using the
setTimeInMillis() method, which requires a millisecond offset from 0:00 UTC ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access