O'Reilly logo

J2ME in a Nutshell by Kim Topley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required