Instant minusMillis() method in Java with Examples
The minusMillis() method of Instant class subtracts specified duration in milliseconds from this instant and returns the result as an instant object. This returned Instant is immutable.
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.
public Instant minusMillis(long millisToSubtract)
Parameters: This method accepts one parameter millisToSubtract which is milliseconds to subtract.
Returns: This method returns the Instant after subtraction of milliSeconds.
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 minusMillis() method:
Returned Instant: 2018-12-30T01:48:10.630Z
current instant: 2018-11-27T05:13:12.132Z Returned Instant: 2018-11-26T19:13:12.132Z