The method of time processing in J2ME

Source: Internet
Author: User
Tags current time difference between two times

The way of expression of time

There are two ways of expressing time in J2ME:

1, with the GMT1970 year January 1 Midnight 12 o'clock and now the difference between the number of milliseconds to represent, this approach is suitable 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.

Related Article

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.

Tags Index: