Java Instant plusSeconds() method

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

This instance is immutable and unaffected by this method call.

Syntax

Parameter

secondsToAdd ? It specifies the seconds to add. It can be either positive or negative.

Return

  • It returns an Instant based on this instant with the specified seconds added
  • The 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-03T13:02:10Z

Example 2

Output:

2018-05-01T20:57:13.972Z
2018-05-02T02:30:33.972Z
2018-05-01T15:23:53.972Z