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


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

Updated on: 30-Jul-2019

210 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements