Get elapsed time in seconds in Java
Description
The following code shows how to get elapsed time in seconds.
Example
// www. j a va2 s . c o m
public class Main {
public static void main(String[] argv) throws Exception {
long start = System.currentTimeMillis();
Thread.sleep(2000);
// Get elapsed time in milliseconds
long elapsedTimeMillis = System.currentTimeMillis() - start;
//
float elapsedTimeSec = elapsedTimeMillis/1000F;
System.out.println(elapsedTimeSec);
}
}
The code above generates the following result.