Return the computer time in milliseconds in Java
Description
The following code shows how to return the computer time in milliseconds.
The value represents the number of milliseconds that has elapsed since January 1, 1970 UTC. To get the string representation of the current computer time, use this:
System.out.println(new java.util.Date());
currentTimeMillis
is useful if you want to time an operation.
Example
/* www .ja v a 2 s. co m*/
public class Main {
public static void main(String[] a) {
long start = System.currentTimeMillis();
// block of code to time
long end = System.currentTimeMillis();
System.out.println("It took " + (end - start) + " milliseconds");
}
}
The code above generates the following result.