Date class, time and date format class

Source: Internet
Author: User
Tags time and date

Date class: Constructs an instance that reacts to the current time.

Date S=new date (); System.out.println (s);

The print variable s can get the current time of the computer, which can be specific to the time unit ' seconds '.

Long Starttime=system.currenttimemillis ();
Long Endtime=system.currenttimemillis ();

StartTime and Endtime count the execution time, which is the time that the code between the two expressions executes. This allows you to calculate the efficiency of the current code execution.


DateFormat: Formats the current time and date.

As in the following section of code:

Date S=new date ();D Ateformat fu=dateformat.getdateinstance (dateformat.full); System.out.println (Fu.format (s));

After using DateFormat, the resulting date format is as follows:

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/8A/1B/wKioL1gnEP-QHq5gAAAGB38Web0337.png-wh_500x0-wm_3 -wmp_4-s_2011948645.png "title=" capture. PNG "alt=" Wkiol1gnep-qhq5gaaagb38web0337.png-wh_50 "/>



SimpleDateFormat: is also formatted with the current time and date, and DateFormat is expressed differently.

As follows:

Date S=new date ();    SimpleDateFormat ff=new SimpleDateFormat ("yyyy years mm DD Day E hh mm min ss sec sss milliseconds"); System.out.println (Ff.format (s));

The effect of running:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/8A/1F/wKiom1gnEdODPdeYAAAMswyzOYc865.png-wh_500x0-wm_3 -wmp_4-s_4206555979.png "title=" Capture 2. PNG "alt=" Wkiom1gnedodpdeyaaamswyzoyc865.png-wh_50 "/>

Date class, time and date format class

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.