Home » Java programming language

Java System class nanoTime() method with example

System class nanoTime() method: Here, we are going to learn about the nanoTime() method of System class with its syntax and example.
Submitted by Preeti Jain, on September 15, 2019

System class nanoTime() method

  • nanoTime() method is available in java.lang package.
  • nanoTime() method is used to return the value of the current system time in nanoseconds.
  • nanoTime() method is static, it is accessible with the class name too.
  • nanoTime() method does not throw any exception.

Syntax:

    public static long nanoTime ();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is long, it returns the current system time in nanoseconds.

Example:

// Java program to demonstrate the example of 
// nanoTime() method of System Class

public class NanoTime {
    public static void main(String[] args) {
        System.out.print("The current time is: ");
        System.out.println(System.nanoTime() + " ns");
    }
}

Output

E:\Programs>javac NanoTime.java
E:\Programs>java NanoTime
The current time is: 4254185681871084 ns



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.