The minusMonths() method of Period class in Java is used to subtract the specified months from given period. This method operates only on MONTHS and does not affect other two YEAR, DAYS.
public Period minusMonths(long monthsToSubtract)
Parameters: This method accepts a single parameter monthsToSubtract which is the number of months to be subtracted from the period.
Return Value: This method returns a Period based on provided period in the input subtracting the specified number of months. It must not be null.
Exceptions: It throws an 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.