SimpleDateFormatDemo1 Conversion of date and string formats

Source: Internet
Author: User

/** *    date overrides the ToString () method and uses a string to describe the time represented by the current date object.  *     such as: mon feb 17 15:36:55 cst 2014 *      actually the string returned by the ToString () method of date has a very clear description of the time, *     but for non-English regions, the string is not friendly enough, We prefer to represent time in a particular region.  *     For example, we are more accustomed to the following style:    2014-02-17 15:36:55  Monday  *     java provides us with a class, SimpleDateFormat, which can complete date and string *     Format conversion between . *     Simply put, SimpleDateFormat is the conversion of strings to date based on a particular date format.  *     For example:  yyyy mm month DD Day--hh:mm:ss  can match  2014 year January 06--13:22:41 *      *     Instantiate simpledateformat sdf = new  First SimpleDateFormat (YYYY-MM-DD); *     *     then convert each other in two formats.  *     Date --- string *     string timestr = sdf.format (date); *     *     String --- Date  *    Date date =  String.parse (TIMESTR);  *     *     */
 Public classSimpleDateFormatDemo1 { Public Static voidMain (string[] args)throwsParseException {//Instantiate SimpleDateFormat FirstSimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd"); //instantiating a dateDate Date =NewDate (); //Date---StringString Timestr =Sdf.format (date); //output the converted stringSystem.out.println (TIMESTR);//2016-04-30//String---DateString time = "2016-12-8"; //parse the string into the date format according to the SDF definition formatDate =Sdf.parse (time); //Output converted dateSYSTEM.OUT.PRINTLN (date);//Thu Dec 00:00:00 gmt+08:00    }}

SimpleDateFormatDemo1 Conversion of date and string formats

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.