Home Java LocalDateTime Methods plusYears() Java LocalDateTime plusYears() Method Definition In Java, plusYears(years) returns a new LocalDateTime that is the given number of years later than the original. The month, the day, and the time of day stay the same.
LocalDateTime is immutable , so the original object never changes. Always keep the result: dt = dt.plusYears(1);. There is one exception: 29 February, explained under "Important" below.
An instance method of java.time.LocalDateTime (since Java 8): call it on a LocalDateTime object. Add import java.time.LocalDateTime; at the top of your file.
Syntax Call it on a LocalDateTime and pass the number of years. A negative number goes the other way.
LocalDateTime start = LocalDateTime.of(2026, 3, 15, 10, 30);
LocalDateTime result = start.plusYears(5); // 2031-03-15T10:30
System.out.println(start); // 2026-03-15T10:30 Call What it does dt.plusYears(n)Returns a new date-time with n years added. dt.minusYears(n)The same idea in the opposite direction. dt.plus(n, ChronoUnit.YEARS)The general form. It does the same thing for this unit. date.plusYears(n)LocalDate has the same method, with the same leap-day rule.
The result is a new object . Calling plusYears() without using the returned value does nothing useful.
Library declarations // java.time.LocalDateTime
public LocalDateTime plusYears(long years) Parameters Parameter Description years (long)The number of years to add. It can be zero or negative.
Return Value Return Value Description LocalDateTimeA new LocalDateTime with the years added. The original is not changed.
Important
If the starting date is 29 February and the new year is not a leap year, Java uses 28 February . Century years such as 2100 are not leap years either, because they are not divisible by 400. Adding years never fails because of the day; it only fails when the year goes beyond the supported range.
Compare with Similar Methods Methods that move a date-time in time:
Method How it differs minusYears(n)The opposite direction for years. plus(n, unit)The general method: you choose the unit as an argument. plusMonths(n)Adds months, so plusMonths(12) equals plusYears(1). plusDays(n)Adds exact days, so a year may be 365 or 366 of them.
Java Examples 1. Anniversaries 2. Leap day 3. Warranty check Example 1 — Print Future Anniversaries A company was founded on 15 March 2026. Print its 1st, 5th, and 10th anniversary.
import java.time.LocalDateTime;
public class LdtPlusYearsDemo {
public static void main(String[] args) {
LocalDateTime founded = LocalDateTime.of(2026, 3, 15, 10, 30);
System.out.println("1st: " + founded.plusYears(1));
System.out.println("5th: " + founded.plusYears(5));
System.out.println("10th: " + founded.plusYears(10));
}
} 1st: 2027-03-15T10:30
5th: 2031-03-15T10:30
10th: 2036-03-15T10:30 How It Works The founding moment. 15 March 2026 at 10:30.Only the year changes. plusYears(1) gives 2027, and the month, the day, and the time stay as they were.Bigger jumps work the same way. plusYears(5) gives 2031 and plusYears(10) gives 2036.The original is unchanged. Each call starts again from founded.Example 2 — Add Years to 29 February Start on a leap day and add 1 year, 4 years, and 76 years (which lands on the non-leap year 2100).
import java.time.LocalDateTime;
public class LdtPlusYearsLeap {
public static void main(String[] args) {
LocalDateTime leapDay = LocalDateTime.of(2024, 2, 29, 12, 0);
System.out.println("+1 year: " + leapDay.plusYears(1));
System.out.println("+4 years: " + leapDay.plusYears(4));
System.out.println("+76 years: " + leapDay.plusYears(76));
}
} +1 year: 2025-02-28T12:00
+4 years: 2028-02-29T12:00
+76 years: 2100-02-28T12:00 How It Works 29 February 2024 exists. 2024 is a leap year.2025 has no 29 February. Java falls back to 28 February 2025.2028 is a leap year. Four years later the leap day exists again, so the result is 29 February 2028.2100 is not a leap year. It is divisible by 100 but not by 400, so the answer is 28 February 2100.Example 3 — Check if a Warranty Is Still Valid A product has a two-year warranty. Work out the end date and test one day before it.
import java.time.LocalDateTime;
public class LdtPlusYearsWarranty {
public static void main(String[] args) {
LocalDateTime bought = LocalDateTime.of(2026, 11, 19, 16, 45);
LocalDateTime warrantyEnds = bought.plusYears(2);
LocalDateTime checkDay = LocalDateTime.of(2028, 11, 18, 10, 0);
System.out.println("warranty ends: " + warrantyEnds);
System.out.println("covered on " + checkDay + ": " + checkDay.isBefore(warrantyEnds));
}
} warranty ends: 2028-11-19T16:45
covered on 2028-11-18T10:00: true How It Works The purchase. 19 November 2026 at 16:45.Add two years. The warranty ends on 19 November 2028 at 16:45.Test a day. checkDay is the 18th of November 2028, at 10:00.isBefore decides. That moment is earlier than the end date, so the answer is true.Frequently Asked Questions How do I add years to a LocalDateTime in Java? Call dt.plusYears(n). It returns a new LocalDateTime, so store it: dt = dt.plusYears(n).
Does plusYears() change the original LocalDateTime? No. LocalDateTime is immutable, so plusYears() returns a new object and leaves the original as it was.
Can I pass a negative number to plusYears()? Yes. A negative number moves the other way, so dt.plusYears(-n) gives the same result as dt.minusYears(n).
What is 29 February plus one year in Java? 28 February of the next year, because the next year is not a leap year. Four years later it is 29 February again.
Is plusYears(1) the same as plusDays(365)? No. A year has 365 or 366 days, so plusYears keeps the same month and day, while plusDays(365) can land one day off.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
7 people found this page helpful
Helpful Share Copy link Suggestion