Android time, date processing dateutils, Systemclock, DateFormat

Source: Internet
Author: User
Tags dateformat time and date

Always use the time and date of some processing, such as: The time interval of a program, date time format ... Remark of


Time and date class commonly used in Java:

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 (); How long after the phone starts (milliseconds, including the phone's deep sleep time)

So-called Android deep Sleep, that is, after the screen is off, do nothing for a while, do not connect the USB, and then after a certain time,
Mobile phone Many services, processes are sleep, no longer run.

Systemclock.uptimemillis (); How long after the phone has been activated (milliseconds, not including the phone's deep sleep time)
Systemclock.currentthreadtimemillis (); How much time the current thread is running (millisecond value, without thread or systemclock.sleep value)

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));

Direct according to format, format time (about format, definition in class)


Android.text.format.DateUtils

Dateutils.formatdatetime (Getapplicationcontext (),//format time, maximum display to minutes. Format of the final parameter setting display
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 represented by the maximum interval relative to the current time: several (minutes, hours, days, weeks, months, years) before/after

Dateutils.getrelativetimespanstring (context, long timemillis);

Returns the parameter time string relative to the current time: displayed on the same day, on different days, showing the day of the month, in different year, showing the date

Dateutils.formatdaterange (Getapplicationcontext (), System.currenttimemillis (), System.currenttimemillis () + 60 * 60 * 3000,
Dateutils.format_show_time)); Returns the distance between two time values of a string



Android time, date processing dateutils, Systemclock, DateFormat

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.

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.