Use the timezone class in

Source: Internet
Author: User
Tags time zones

Use the timezone class in

Author: Chen yuefeng

From: http://blog.csdn.net/mailbomb

 

In terms of time expression, the concept of time zone is often used. In j2s, there is a special class-timezone class.

Geographically, the Earth is divided into 24 time zones. The Beijing time in China belongs to the GMT +, and the Urumqi time belongs to the GMT +. The default Implementation of time in the program is based on the London time, this results in eight hours of time difference. Therefore, to make your program more universal, the cldc API of j2-based implements the time zone class.

The timezone class is a Java. util package, and the class in j2se is a simplified timezone. This class is an abstract class. Pay attention to it when using it.

To obtain the default time zone of the region used by the mobile phone, use the following code:

Timezone defaultzone = timezone. getdefault ();

For example, if your mobile phone is in China, it is obtained as the UTC + 8 zone. If it is in another region, it is the time zone object of another region.

In reality, each time zone has an ID that represents the time zone. However, in the implementation process of timezone, only a part is implemented. The code for obtaining available time zone IDS is as follows:

String [] listid = timezone. getavailableids ();

In this way, you can obtain the time zone ID supported by the mobile phone.

After you get the default time zone, you can also get the difference between the time zone and the London time. The timezone is the created time zone object. The method is as follows:

Int offset = timezone. getrawoffset ();

You can use the following method to obtain the ID of the current time zone object:

String id = timezone. GETID ();

Compared with the timezone in j2se, the implementation of this class is not provided in j2se, but the implementation of this class is handed over to the mobile phone manufacturer for implementation. This content is transparent to the j2se developers, the actual development process does not affect the specific use.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.