Get elapsed time in seconds : Timing « Development Class « Java






Get elapsed time in seconds

  
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);
  }
}

   
    
  








Related examples in the same category

1.Compute and display elapsed time of an operation
2.Get system time using System class
3.Class for program event timing
4.Get elapsed time in milliseconds
5.Get elapsed time in minutes
6.Get elapsed time in hours
7.Get elapsed time in days
8.Get time in milliseconds using Java Calendar
9.java.util.concurrent.TimeUnit: convert between milliseconds and days
10.Get seconds since