Time to handle the Raiders in J2ME
Author: Chen Yuefeng
From: http://blog.9cbs.neet/mailbomb
Time processing is quite common in program development, and the following is a brief description for time processing.
First, time expression
There are two ways to express in J2ME:
1, with the GMT to represent the number of milliseconds from January 1, 1970 and now
This approach is suitable for comparing differences between two times.
2, expressed in the form of object
Second, time processing related classes
Time processing involves three classes in J2ME:
1, SYSTEM class
Long Time = system. currenttimemillis ();
Using this method can obtain the current time, the expression method of time is the first one mentioned above.
2, DATE class
Date Date = new date ();
Get the current time, use the object's form to perform expression.
3, Calendar class
Calendar Calendar = Calendar. GetInstance ();
Third, the specific operation of time processing
1, the conversion of the above three expressions:
a) Convert the time obtained by the System class into a Date object
Date Date = New Date (System. CurrentTimeMillis ());
b) Convert the object of the DATE type to the Calendar type object
Calendar Calendar = Calendar. GetInstance ();
Date Date = new date ();
Calendar.SetTime (date);
2. Use Calendar to complete some date operations:
Calendar is the most commonly used in time handling is also the most powerful class, which can be used to get a certain time, and the Weekday information.
Get Date:
Calendar Calendar = Calendar. GetInstance ();
......
INT day = calendar.get (Calendar. Date);
Date, year, weeks, and this similar.
It should be noted that: Calendar represents the number of months and actual differences 1, namely January 0, said in February 1, ...... Demo 11 in December.