Java Date Time - Duration plusNanos(long nanosToAdd) example








Duration plusNanos(long nanosToAdd) returns a copy of this duration with the specified duration in nanoseconds added.

Syntax

plusNanos has the following syntax.

public Duration plusNanos(long nanosToAdd)

Example

The following example shows how to use plusNanos.

import java.time.Duration;
import java.time.LocalTime;
/*  w w  w.j  a v  a2  s. c  om*/
public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
    duration = duration.plusNanos(1000);
    System.out.println(duration.getNano());

  }
}

The code above generates the following result.