Get the current time (date-> string)

Source: Internet
Author: User

System. Out. println (New java. Text. simpledateformat ("yyyy-mm-dd hh: mm: SS"). Format (new date ()));

 

Run: 10:31:38

 

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Get current time

 

Obtain the current number of milliseconds for the difference in running time:

Long start = system. currenttimemillis ();

Long end = system. currenttimemillis ();

System. Out. println ("time:" + (end-Start ));

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

First, system. currenttimemillis () generates a current millisecond, which is actually the number of milliseconds since, January 1, January 1, 1970. Date () is actually equivalent to date (system. currenttimemillis (); because the date class also has a construction date (long date), it is used to calculate the millisecond difference between long seconds and January 1, January 1, 1970.
After obtaining the number of milliseconds, we can calculate the current year, month, day, week, but this is not calculated because there is a calendar. The final result of the calendar is the year, month, day, week time zone.

System. currenttimemillis () obtains the time distance from 00:00:00. 000 to the current time. The type is long.

String. valueof (system. currenttimemillis () can be converted to the following type:

Long Ct = system. currenttimemillis ();
String T = string. valueof (CT );

In fact, the above string T is equivalent to CT + "";
Only convert to string 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.