Android system date-time acquisition

Source: Internet
Author: User
Tags dateformat
[Java]View Plain copy print?                Import Java.text.SimpleDateFormat;        SimpleDateFormat formatter = new SimpleDateFormat ("YYYY year mm month DD Day HH:mm:ss"); Date curdate = new Date (System.currenttimemillis ());//Get current time String str = Formatter.format (curd ATE);

Can get the current year or so, can also be written separately: [Java] view plain copy print?        SimpleDateFormat Sdateformat = new SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss"); String date = Sdateformat.format (new java.util.Date ());

If you want to get the current year, you can write this (get the same time or seconds): Java code

[Java] view plain copy print?     SimpleDateFormat sdf=new SimpleDateFormat ("yyyy-mm"); String Date=sdf.format (New Java.util.Date ());

And, of course, the time zone can be specified (stay):

[Java] view plain copy print?   Df=dateformat.getdatetimeinstance (Dateformat.full,dateformat.full,locale.china); System.out.println (New Date ()) (Df.format);

  How to get Android system time is 24-hour or 12-hour system [Java]   View plain copy print? Contentresolver cv = this.getcontentresolver ();           string strtimeformat = android.provider.settings.system.getstring (cv,                                                android.provider.settings.system.time_12_24);                    if (Strtimeformat.equals (")")           {                  LOG.I ("Activity", ";  ")           

[Java] view plain copy print?   Calendar C = calendar.getinstance (); Get system date: Year = C.get (calendar.year) month = C.GRT (calendar.month) day = C.get (calendar.da                     Y_of_month) Obtain the system time: Hour = C.get (Calendar.hour_of_day); minute = C.get (Calendar.minute)

use calendar to get


[Java]   View plain copy print? Calendar c = calendar.getinstance ();  

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.