Java gets the month and day method of the current time

Source: Internet
Author: User
Tags time in milliseconds

Java gets the year, month, day, hour, minute, and number of seconds of the current time.

1      Public Static voidGetDateTime ()throwsparseexception{2Calendar now =calendar.getinstance ();3System.out.println ("Year:" +Now.get (calendar.year));4System.out.println ("Month:" + (Now.get (calendar.month) + 1) + "");5System.out.println ("Day:" +Now.get (Calendar.day_of_month));6System.out.println ("When:" +Now.get (Calendar.hour_of_day));7System.out.println ("min:" +Now.get (Calendar.minute));8System.out.println ("Seconds:" +Now.get (Calendar.second));9System.out.println ("Current time milliseconds:" +Now.gettimeinmillis ());Ten System.out.println (Now.gettime ()); One  ADate d =NewDate (); - System.out.println (d); -SimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); theString Datenowstr =Sdf.format (d); -SYSTEM.OUT.PRINTLN ("Formatted date:" +datenowstr); -              -String str = "2012-1-13 17:26:33";//the same format as the SDF definition above +Date today =sdf.parse (str); -System.out.println ("string turns into date:" +today); +}

Output Result:

2014-12-26
Year: 2014
Month: 12
Day: 26
Hours: 15
Points: 6
Seconds: 35
Current time in milliseconds: 1419577595014
Fri Dec 15:06:35 CST 2014
Fri Dec 15:06:35 CST 2014
Date formatted: 2014-12-26 15:06:35
String converted to date: Fri Jan 17:26:33 CST 2012

Java gets the month and day method of the current 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.