Android Get time

Source: Internet
Author: User
Tags date1 dateformat

First of all, first of all, the following Java can be used in a normal way:

1 ImportJava.text.DateFormat;2 ImportJava.text.SimpleDateFormat;3 ImportJava.util.Calendar;4 Importjava.util.Date;5 ImportJava.util.Locale;6 7  Public classGetDate {8 9     /**Ten      * @paramargs One      */ A      Public Static voidMain (string[] args) { -  -         //Get date and time (12 hour system) theSimpleDateFormat Sdateformat =NewSimpleDateFormat ( -"Yyyy-mm-dd hh:mm:ss");//Show Rules -String date = Sdateformat.format (Newjava.util.Date ()); -          + System.out.println (date); -          +         //Get date and time (12 hour system) ASimpleDateFormat SDATEFORMAT1 =NewSimpleDateFormat ( at"yyyy mm month DD Day Hh:mm:ss");//Show Rules -String date1 = Sdateformat.format (Newjava.util.Date ()); -                  - System.out.println (date1); -          -         //set the time zone to display times using the date () method inDateFormat df=dateformat.getdatetimeinstance (Dateformat.full,dateformat.full,locale.china);//China -System.out.println (Df.format (NewDate ())); to              +         //24 Hour System -Calendar C =calendar.getinstance ();  the         //Get system Date: *         intYear =C.get (calendar.year); $         intmonth = C.get (calendar.month) +1;//get 1 less months than the real monthPanax Notoginseng         intDay =C.get (calendar.day_of_month); -         //Get system time: the         inthour =C.get (Calendar.hour_of_day);  +         intminute =C.get (calendar.minute); A          theSystem.out.println (year+ ":" +month+ ":" +day+ ":" +hour+ ":" +minute+ ""); +          -         //Time t=new time ();//or time T=new time ("Gmt+8"), plus time zone data.  $     } $  -}

Can directly test to run on the computer to see the difference.

Here are the results:

2016-03-08    12:35:342016-03-08    12:35:34March 8, 2016 Tuesday 12:35 A.M. 34 sec CST2016:3:8:0:35

Below you can put down the methods available for Android:

  = this  .getcontentresolver ();      String strtimeformat  = Android.provider.Settings.System.getString (CV,      ANDROID.PROVIDER.SETTINGS.SYSTEM.TIME_12_24);  if  (Strtimeformat.equals (" "Activity", "
  take time to get: Java code: time t  =new  Time () ; //  T.settonow (); //  get system time.       int  year = T.year;       int  month = T.month;       int  date = T.monthday;  int  hour = t.hour; //  0-23  int  minute = T.minute;  int  second = T.second; 

The two above have not been tested, but time acquisition is not recommended

Android Get time

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.