Period plusMonths() method in Java with Examples
The plusMonths() method of Period class in Java is used to add the specified months to this current period. This functions operates only on MONTHS and does not affect YEARS and DAYS.
public Period plusMonths(long monthsToAdd)
Parameters: This method accepts a single parameter monthsToAdd which is the number of months to be added to the period.
Return Value: This method returns a Period based on provided period in the input adding the specified number of months. It must not be null.
Exceptions: This method throws an ArithmeticException if numeric overflow occurs.
Below program illustrates the above method:
Program 2: Months to be added can be negative.
My Personal Notes arrow_drop_up
Please Login to comment...