Conversion and application of date formats in Java

Source: Internet
Author: User
Tags date1 dateformat

There are 3 main classes in Java for date format conversions DateFormat, SimpleDateFormat, Calendar

1.SimpleDateFormat

The class is a subclass of DateFormat, and the formatting of the general date is to instantiate the class implementation

The specific application is as follows

 PackageCom.gree.java;ImportJava.text.SimpleDateFormat;ImportJava.util.Calendar;Importjava.util.Date;ImportJava.util.logging.SimpleFormatter; Public classSimpledate { Public Static voidmain (String [] args) {SimpleDateFormat a=NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");//Full date format, 24-hour systemSimpleDateFormat b=NewSimpleDateFormat ("Yyyy-mm-dd hh:mm:ss a");//Full date format, 12-hour systemSimpleDateFormat c=NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");//get the date after 5 daysSimpleDateFormat d=NewSimpleDateFormat ("Yyyy-mm-dd");//get month and day formatSimpleDateFormat e=NewSimpleDateFormat ("yyyy");//Get yearSimpleDateFormat f=NewSimpleDateFormat ("MM");//Get MonthSimpleDateFormat g=NewSimpleDateFormat ("DD");//Get DayCalendar Calendar=calendar.getinstance (); Calendar.add (Calendar.date,5); Date Date1=NewDate (); Date Date=Calendar.gettime ();    System.out.println (A.format (date));    System.out.println (B.format (date1));    System.out.println (C.format (date1));    System.out.println (D.format (date1));    System.out.println (E.format (date1));    System.out.println (F.format (date1)); System.out.println (G.format (date1));//System.out.println (G.format (date1));           }}
The results are as follows:
2014-11-18 16:36:302014-11-13 04:36:30 pm 2014-11-13 16:36:302014-11-1320141113

Conversion and application of date formats in 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: 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.