Java LocalDate plusYears() Method
Example
Add 5 years to a date:
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate myDate = LocalDate.of(2026, 1, 15);
System.out.println(myDate.plusYears(5));
}
}
Definition and Usage
The plusYears() method returns a new date, a number of years after the original date. The original date is not changed.
If the original date is February 29 and the new year is not a leap year, February 28 is used.
Syntax
public LocalDate plusYears(long yearsToAdd)
Parameter Values
| Parameter | Description |
|---|---|
| yearsToAdd | Required. The number of years to add. It can be negative. |
Technical Details
| Returns: | A new LocalDate object with the years added. |
|---|
Related Pages
❮ Date and Time Methods