Java Instant plusNanos() method

The plusNanos() method of Java Instant class is used to return a copy of the instant with the specified duration in nanoseconds added

This instance is immutable and unaffected by this method call.

Syntax

Parameter

nanosToAdd ? It specifies the nanoseconds to add. It can be either positive or negative.

Return

  • It returns an Instant based on this instant with the specified nanoseconds added
  • he return value cannot be null.

Exception

DateTimeException - If the result exceeds the maximum or minimum instant

ArithmeticException - If numeric overflow occurs

Example 1

Output:

2018-02-03T10:15:40Z

Example 2

Output:

0
70000

Example 3

Output:

2018-05-01T20:57:16.073Z
2018-05-01T20:57:16.075Z
2018-05-01T20:57:16.070Z