The plusSeconds() method of Instant class adds seconds value passed as parameter to this instant and return the result as an instant object. This returned Instant is immutable.
public Instant plusSeconds(long secondsToAdd)
Parameters: This method accepts one parameter secondsToAdd which is seconds to be added.
Returns: This method returns Instant after adding the seconds.
Exception: This method throws following exceptions:
- DateTimeException: if the result exceeds the maximum or minimum instant.
- ArithmeticException: if numeric overflow occurs.
Below programs illustrate the plusSeconds() method:
Instant: 2018-10-28T19:34:50.630Z Returned Instant: 2018-10-29T18:54:50.630Z
Current instant: 2018-11-28T05:39:46.572Z Returned Instant: 2018-12-08T23:59:46.572Z
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.