Java LocalDateTime plusYears() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Java 8+

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.

Java
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
CallWhat 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
// java.time.LocalDateTime
public LocalDateTime plusYears(long years)

Parameters

ParameterDescription
years (long)The number of years to add. It can be zero or negative.

Return Value

Return ValueDescription
LocalDateTimeA new LocalDateTime with the years added. The original is not changed.

Compare with Similar Methods

Methods that move a date-time in time:

MethodHow 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

Example 1 — Print Future Anniversaries

A company was founded on 15 March 2026. Print its 1st, 5th, and 10th anniversary.

Java
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));
    }
}

How It Works

  1. The founding moment. 15 March 2026 at 10:30.
  2. Only the year changes. plusYears(1) gives 2027, and the month, the day, and the time stay as they were.
  3. Bigger jumps work the same way. plusYears(5) gives 2031 and plusYears(10) gives 2036.
  4. 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).

Java
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));
    }
}

How It Works

  1. 29 February 2024 exists. 2024 is a leap year.
  2. 2025 has no 29 February. Java falls back to 28 February 2025.
  3. 2028 is a leap year. Four years later the leap day exists again, so the result is 29 February 2028.
  4. 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.

Java
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));
    }
}

How It Works

  1. The purchase. 19 November 2026 at 16:45.
  2. Add two years. The warranty ends on 19 November 2028 at 16:45.
  3. Test a day. checkDay is the 18th of November 2028, at 10:00.
  4. isBefore decides. That moment is earlier than the end date, so the answer is true.

Frequently Asked Questions

Call dt.plusYears(n). It returns a new LocalDateTime, so store it: dt = dt.plusYears(n).
No. LocalDateTime is immutable, so plusYears() returns a new object and leaves the original as it was.
Yes. A negative number moves the other way, so dt.plusYears(-n) gives the same result as dt.minusYears(n).
28 February of the next year, because the next year is not a leap year. Four years later it is 29 February again.
No. A year has 365 or 366 days, so plusYears keeps the same month and day, while plusDays(365) can land one day off.

Next: query()

Run a query on the date-time and get a result of any type.

query() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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