This method returns a new instance of local date by adding the specified amount to the month field adjusting other fields if necessary. The original instance is not changed.
The provided monthsToAdd can be negative, in that case months will be subtracted.
package com.logicbig.example.localdate;
import java.time.LocalDate;
public class PlusMonthsExample {
public static void main (String... args) {
LocalDate d = LocalDate.of(2001, 11, 22);
LocalDate d2 = d.plusMonths(10);
System.out.println(d2);
LocalDate d3 = d.plusMonths(20);
System.out.println(d3);
LocalDate d4 = d.plusMonths(-20);
System.out.println(d4);
}
}
Output
2002-09-22
2003-07-22
2000-03-22