Java Instant minusSeconds() method

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

This instance is immutable and unaffected by this method call.

Syntax

Parameters

secondsToSubtract - The seconds to subtract, positive or negative.

Return

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

Exceptions

DateTimeException - If the result exceeds the maximum or minimum instant.

ArithmeticException - If numeric overflow occurs.

Example 1

Output:

The output will be like this.

2017-02-03T10:37:20Z

Example 2

Output:

The output will be like this.

2017-05-01T20:57:36.857Z
2017-05-01T12:37:36.857Z
2017-05-02T05:17:36.857Z