Test:
Effect:
System.currenttimemillis ();
currenttimemillis () returns the current time in milliseconds , and returns the time difference (measured in milliseconds) between the current and midnight January 1, 1970 of the coordinated GMT. Note that when the time unit of the return value is milliseconds, the granularity of the value depends on the underlying operating system, and the granularity may be greater. For example, many operating systems measure time in dozens of milliseconds.
Main usage:
(1) To test the running time of the program:
as shown in
(2) Control thread time, refresh screen frequency:
time1 = System.currenttimemillis (); ------Path Code Snippet------time2 = System.currenttimemillis (), if (Time2-time1 <) {try {thread.sleep (time2-time1));} C Atch (Interruptedexception e) {}}
(3) generate a file name that is not duplicated:
Public String GetName () { Stringdate1 = null; SIMPLEDATEFORMATSDF1 = new SimpleDateFormat ("Yyyymmddhhmmsssss"); date1= Sdf1.format (New Date (System.currenttimemillis ())) + ". txt"; return date1;}
(4) Get date type
Long currenttime = System.currenttimemillis (); SimpleDateFormat formatter = new SimpleDateFormat ("YYYY year-MM month DD Day-hh mm min SS second") Date date = new Date (currenttime); System.out.println (Formatter.format (date)); The result of the operation is as follows: Current time: 2015-January 16-16 42 minutes 46 seconds
Java test method run time System.currenttimemillis ();