1long start = System.currentTimeMillis();
2class.method();
3long time = System.currentTimeMillis() - start;
1long startTime = System.nanoTime();
2methodToTime();
3long endTime = System.nanoTime();
4
5long duration = (endTime - startTime); //divide by 1000000 to get milliseconds.
1Instant start = Instant.now();
2Thread.sleep(63553);
3Instant end = Instant.now();
4System.out.println(Duration.between(start, end)); // prints PT1M3.553S
5
1long startTime = System.nanoTime();
2.....your program....
3long endTime = System.nanoTime();
4long totalTime = endTime - startTime;
5System.out.println(totalTime);
6