Doubts about the Java time format

Source: Internet
Author: User

In Java, date () is no type one said, we call the time format, time type refers to the format after conversion to a string, does not mean the format of Date ();

  public void testdate ()  {      //defines the time, and its format defaults to:tue  jun 09 11:11:30 gmt+08:00 2015 This style       Date date  = new date ();           //output: Tue Jun 09  11:11:30 GMT+08:00 2015           SYSTEM.OUT.PRINTLN (date);        //define time conversion format        dateformat dfm =new simpledateformat ("Yyyy-mm-dd hh:mm:ss");       //converts a time into a string of the specified format           string time= Dfm.format (date);            //string after output transition format: 2015-06-09  11:35:52          system.out.println (Time);        try {           /* will be formatted as "YYYY-MM-DD HH:MM:SS"             *  date display is still tue  when converted to time jun 09 11:11:30 gmt+08:00 2015 This style              */           date dm=dfm.parse ( Time.tostring ());                // Verify that the output is:tue jun 09 11:35:52 gmt+08:00 2015                system.out.println (DM);                //converted to string output as: tue jun 09 11:35:52 gmt+ 08:00 2015                System.out.println (dm.tostrING ());      } catch  (parseexception e)  {            e.printstacktrace ();       }  }   background output is:         tue jun 09 11:11:30  GMT+08:00 2015        2015-06-09 11:36:48         Tue Jun 09 11:36:48 GMT+08:00 2015         tue jun 09 11:36:48 gmt+08:00 2015

This article is from the "9891958" blog, please be sure to keep this source http://9901958.blog.51cto.com/9891958/1659992

Doubts about the Java time format

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.