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 ...

Get J2ME in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.