Java Instant plusMillis() method

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

This instance is immutable and unaffected by this method call.

Syntax

Parameter

millisToAdd ? It specifies the milliseconds to add. It can be either positive or negative.

Return

  • It returns an Instant based on this instant with the specified milliseconds 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:

2016-12-03T10:15:40Z

Example 2

Output:

The output will be like this.

2018-08-01T20:57:18.164Z 2018-08-01T20:57:18.564Z 2018-08-01T20:57:17.764Z 2018-08-01T19:50:38.164Z