CodesJava

Easy learning with example program codes

Java calculate elapsed time


Java calculate elapsed time example

package com.codesjava;
 
import java.util.concurrent.TimeUnit;
 
public class ElapsedTimeTest {
  public static void main(String args[]) throws InterruptedException{
	  //start
	  long lStartTime = System.nanoTime();
	  //task
	  calculation();
	  //end
	  long lEndTime = System.nanoTime();
	  //time elapsed
	  long output = lEndTime - lStartTime;
	  System.out.println("Elapsed time in milliseconds: " + output / 1000000);
  }
 
  private static void calculation() throws InterruptedException {
      //Sleep 3 seconds
      TimeUnit.SECONDS.sleep(3);
  }
}

Output:

Elapsed time in milliseconds: 3002
Posted in Date   


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki