Java Program to get the current value of the system timer in nanoseconds

Java 8Object Oriented ProgrammingProgramming

Use System.nanoTime() method in Java to get the current value of the system timer in nanoseconds. It d returns the current value of the most precise available system timer, in nanoseconds.

We are getting the system timer value in a long type −

long res = System.nanoTime();

The following is an example −

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      long res = System.nanoTime();
      System.out.println("Current Value: " + res + " nanoseconds");
   }
}

Output

Current Value: 49908709882168 nanoseconds
raja
Published on 21-Dec-2018 06:54:33
Advertisements