Instant minusSeconds() method in Java with Examples
The minusSeconds() method of Instant class subtracts specified second value from this instant and return the result as an instant object. This instant is immutable.
public Instant minusSeconds(long secondsToSubtract)
Parameters: This method accepts one parameter secondsToSubtract which is seconds to be subtracted.
Returns: This method returns Instant after subtraction of seconds.
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.
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 minusSeconds() method:
Initialize instant: 2018-10-30T09:05:55.130Z Returned Instant: 2018-10-30T07:54:15.130Z
Current instant: 2018-11-27T06:44:04.901Z Returned Instant: 2018-11-26T15:44:04.901Z