Obtain the system time in android

Source: Internet
Author: User

 

1. SimpleDateFormat formatter = new SimpleDateFormat ("MM dd, yyyy HH: mm: ss ");

2. Date curDate = new Date (System. currentTimeMillis (); // obtain the current time

3. String str = formatter. format (curDate );

4. import java. text. simpleDateFormat; SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss"); Date curDate = new Date (System. currentTimeMillis (); // obtain the current time String str = formatter. format (curDate); you can obtain the current year and month, or write separately:

5.

6. Java code

7. SimpleDateFormat sDateFormat = new SimpleDateFormat ("yyyy-MM-dd hh: mm: ss ");

8. String date = sDateFormat. format (new java. util. Date ());

9. 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 and month, you can write this statement (only get the same time or second ):

10.

11. Java code

12. SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM ");

13. String date = sdf. format (new java. util. Date ());

14. simpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM"); String date = sdf. format (new java. util. date (); of course, you can specify the time zone (to be ):

15.

16. df = DateFormat. getDateTimeInstance (DateFormat. FULL, DateFormat. FULL, Locale. CHINA );

17. System. out. println (df. format (new Date ()));

From the wanli_smile Column

 

 

 

 

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.