Period minus() method in Java with Examples
The minus() method of Period class in Java is used to subtract the given amount of period from the specified period. This functions operates separately on YEAR, MONTH and DAY.
Note: Normalization is not performed. 12 months and 1 year are different.
public Period minus(TemporalAmount amountToSubtract)
Parameters: This method accepts a single parameter amountToSubtract, which is the amount to subtract from this period. It must not be null.
Return Value: This method returns a Period based on the given period with the requested period subtracted, and this must not be null.
- DateTimeException: This exception is returned if the specified amount has a non-ISO chronology or contains an invalid unit.
- ArithmeticException: This exception is caught if numeric overflow occurs.
Below programs illustrate the above method:
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.