J2ME in the time processing in the whole strategy

Source: Internet
Author: User
Tags date current time difference between two times expression
Introduction time processing in the development of the program is quite common, the following for the time to do a simple explanation.
The way of expression of time
There are two ways of expressing time in J2ME:
1, and GMT1970 year January 1 Midnight 12 o'clock and now the difference between the number of milliseconds to represent
This is a good way to compare the difference between two times.
2, in the form of objects to express
Second, the related class of time processing
Time processing involves three classes in J2ME:
1. System class
Long time = System. Currenttimemillis ();
The method can be used to obtain the current time, and the expression of time is the first mentioned above.
2. Date class
Date date = new Date ();
Get the current time, use the form of the object to express.
3. Calendar class
Calendar Calendar = Calendar. GetInstance ();
Third, the specific operation of time processing
1, the above three kinds of expression conversion:
A) Converts the time obtained by the system class to the Date object
Date date = new Date (System. Currenttimemillis ());
b Converts a date-type object to a calendar-type Object
Calendar Calendar = Calendar. GetInstance ();
Date date = new Date ();
Calendar.settime (date);
2, use calendar to complete some date operation:
Calendar is the most commonly used and most powerful class in time processing, and can be used to get information about the date and day of the week.
Date of acquisition:
Calendar Calendar = Calendar. GetInstance ();
......
int day = Calendar.get (calendar. DATE);
Get the date, year, week operation and this similar.

Note that the number of months in the calendar and the actual difference is 1, that is, January by the number 0, February with the number 1, said ... December with the number 11 expressed.

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.