Date class and date formatting classes for Java

Source: Internet
Author: User
Tags dateformat string format

Date class:

1Date Date =NewDate ();//gets the current system time2System.out.println ("Year:" +date.getyear ());3         4Calendar calendar = Calendar.getinstance ();//gets the current system time. 5System.out.println ("Year:" +Calendar.get (calendar.year));6System.out.println ("Month:" + (Calendar.get (calendar.month) +1));7System.out.println ("Day:" +Calendar.get (;8         9System.out.println ("When:" +Calendar.get (Calendar.hour_of_day));TenSystem.out.println ("min:" +Calendar.get (Calendar.minute)); OneSystem.out.println ("seconds:" + calendar.get (Calendar.second));

Date formatting classes:

1 /*date formatting class SimpleDateFormat2 * Role 1: Can convert the date to the specified format string format ()3 * Function 2: You can convert a character to the corresponding date. Parse ()4 */5Date Date =NewDate ();//gets the current system time. 6SimpleDateFormat DateFormat =NewSimpleDateFormat ("yyyy mm month DD Day HH:mm:ss");//A date formatting object was created using the default format. 7String time = Dateformat.format (date);//you can convert a date to a string in the specified format8SYSTEM.OUT.PRINTLN ("Current system time:" +Time );9 TenString birthday = "December 26, 2000 11:29:08"; OneDate date2 = Dateformat.parse (birthday);//Note: The specified string format must be consistent with the SimpleDateFormat pattern.  ASystem.out.println (DATE2);

Date class and date formatting classes for Java

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: 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.