Java LocalDate plusMonths() Method
Example
Add months to two dates:
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate date1 = LocalDate.of(2026, 1, 15);
LocalDate date2 = LocalDate.of(2026, 1, 31);
System.out.println(date1.plusMonths(3));
System.out.println(date2.plusMonths(1));
}
}
Definition and Usage
The plusMonths() method returns a new date, a number of months after the original date. The original date is not changed.
If the day does not exist in the new month, the last day of that month is used. For example, January 31 plus one month gives February 28 (or February 29 in a leap year).
Syntax
public LocalDate plusMonths(long monthsToAdd)
Parameter Values
| Parameter | Description |
|---|---|
| monthsToAdd | Required. The number of months to add. It can be negative. |
Technical Details
| Returns: | A new LocalDate object with the months added. |
|---|
Related Pages
❮ Date and Time Methods