I have a Java application that I\'ve been working on and I just realized that the program has to return a value in less than a minute, but don\'t know how to find or display
You can use 2 APIs provided by System
class
Sample Code
public class TestTimeTaken {
public static void main(String args[]) throws InterruptedException{
long startTimeNanoSecond = System.nanoTime();
long startTimeMilliSecond = System.currentTimeMillis();
//code
Thread.sleep(1000);
//code
long endTimeNanoSecond = System.nanoTime();
long endTimeMilliSecond = System.currentTimeMillis();
System.out.println("Time Taken in "+(endTimeNanoSecond - startTimeNanoSecond) + " ns");
System.out.println("Time Taken in "+(endTimeMilliSecond - startTimeMilliSecond) + " ms");
}
}