Java Date Time - Duration ofNanos(long nanos) example








Duration ofNanos(long nanos) creates a Duration representing a number of nanoseconds.

The seconds and nanoseconds are extracted from the specified nanoseconds.

Syntax

ofNanos has the following syntax.

public static Duration ofNanos(long nanos)

Example

The following example shows how to use ofNanos.

import java.time.Duration;

public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.ofNanos(10);
    System.out.println(duration);
  }
}

The code above generates the following result.