Android time and date Processing DateUtils, SystemClock, and DateFormat
It always takes some processing of time and date, such as the time interval of a program and the formatting of date and time... note
Common java time and date class:
Java. util. Date
Java. util. Calendar
Java. text. DateFormat
Java. text. SimpleDateFormat
There is also a way to get the System time: System. currentTimeMillis ();
In android:
Android. OS. SystemClock
Android. text. format. DateFormat
Android. text. format. DateUtils
Android. OS. SystemClock
SystemClock. elapsedRealtime (); // the time after which the mobile phone starts (millisecond value, including the deep sleep time of the mobile phone)
The so-called android sleep, that is, after the screen is closed, no operation is performed for a period of time, no usb is connected, and then after a certain period of time,
Many services and processes on mobile phones are sleeping and no longer running.
SystemClock. uptimeMillis (); // how long has the phone been started (millisecond value, excluding the deep sleep time of the phone)
SystemClock. currentThreadTimeMillis (); // how long the current thread has been running (millisecond value, excluding the value of thread or systemclock. sleep)
Android. text. format. DateFormat
DateFormat. format ("yyyy-MM-dd HH: mm: ss", System. currentTimeMillis ());
DateFormat. format ("yy/MM/dd", Calendar. getInstance ());
DateFormat. format ("yyyy", new Date (2048,12, 01 ));
Based on the format and time (the format is defined in the class)
Android. text. format. DateUtils
DateUtils. formatDateTime (getApplicationContext (), // The formatting time, which can be up to minutes. Finally, set the display format for the parameter.
System. currentTimeMillis (),
DateUtils. FORMAT_24HOUR | DateUtils. FORMAT_SHOW_DATE | DateUtils. FORMAT_SHOW_TIME
| DateUtils. FORMAT_SHOW_YEAR | DateUtils. LENGTH_LONG | DateUtils. FORMAT_ABBREV_MONTH );
DateUtils. getRelativeTimeSpanString (System. currentTimeMillis () + 60*4000 ));
// Returns the string (minutes, hours, days, weeks, months, and years) represented by the maximum interval relative to the current time.
DateUtils. getRelativeTimeSpanString (context, long timeMillis );
// Returns the time string of the parameter relative to the current time: display time on the same day; display month and day on different days; display year, month, and day on different years
DateUtils. formatDateRange (getApplicationContext (), System. currentTimeMillis (), System. currentTimeMillis () + 60x60*3000,
DateUtils. FORMAT_SHOW_TIME); // returns the string between two time values.