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