Java Instant minusNanos() method

The minusNanos () method of Java Instant class is used to return a copy of this instant with the specified duration in nanoseconds subtracted.

This instance is immutable and unaffected by this method call.

Syntax

Parameters

nanosToSubtract - The nanoseconds to subtract, positive or negative.

Return

An Instant based on this instant with the specified nanoseconds subtracted, not null.

Exceptions

DateTimeException - If the subtraction cannot be made

ArithmeticException - If numeric overflow occurs

Example 1

Output:

The output will be like this.

2017-05-01T20:57:38.879Z
2017-05-01T20:57:38.579Z

Example 2

Output:

The output will be like this.

2017-05-01T20:57:40.934Z

2017-05-01T20:57:40.434Z