LocalDate plusYears() method in Java with Examples Last Updated : 30 Jul, 2019 Comments Improve Suggest changes Like Article Like Report The plusYears() method of LocalDate class in Java is used to add the number of specified years in this LocalDate and return a copy of LocalDate. This method adds the years field in the following steps: Add the years to the year field. Check if the date after adding years is valid or not. If date is invalid then method adjust the day-of-month to the last valid day. For example, 2016-02-29 (leap year) plus one year gives date 2017-02-29 but this is invalid result, so the last valid day of the month, 2017-02-28, is returned.This instance is immutable and unaffected by this method call. Syntax: public LocalDate plusYears(long yearsToAdd) Parameters: This method accepts a single parameter yearsToAdd which represents the years to add, may be negative. Return value: This method returns a LocalDate based on this date with the years added, not null. Exception: This method throws DateTimeException if the result exceeds the supported date range. Below programs illustrate the plusYears() method: Program 1: Java // Java program to demonstrate // LocalDate.plusYears() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalDate object LocalDate date = LocalDate.parse("2018-11-13"); // print instance System.out.println("LocalDate before" + " adding years: " + date); // add 3 years LocalDate returnvalue = date.plusYears(3); // print result System.out.println("LocalDate after " + " adding years: " + returnvalue); } } Output: LocalDate before adding years: 2018-11-13 LocalDate after adding years: 2021-11-13 Program 2: Java // Java program to demonstrate // LocalDate.plusYears() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalDate object LocalDate date = LocalDate.parse("2016-02-29"); // print instance System.out.println("LocalDate before" + " adding years: " + date); // add 2 years LocalDate returnvalue = date.plusYears(2); // print result System.out.println("LocalDate after " + " adding years: " + returnvalue); } } Output: LocalDate before adding years: 2016-02-29 LocalDate after adding years: 2018-02-28 References: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDate.html#plusYears(long) Comment More infoAdvertise with us Next Article LocalDate plusYears() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-time package Java-LocalDate Practice Tags : Java Similar Reads LocalDateTime plusYears() method in Java with Examples The plusYears() method of LocalDateTime class is used to return a copy of this date-time with the specified years added. Syntax: public LocalDateTime plusYears(long years) Parameter: It accepts a single parameter years which specifies the years to add which may be negative. Return Value: This method 1 min read LocalDate minusYears() method in Java with Examples The minusYears() method of a LocalDate class is used to subtract the number of specified years from this LocalDate and return a copy of LocalDate. This method subtracts the years field in the following steps: Firstly, it subtracts the years from the year field in this LocalDate. Check if the date af 2 min read LocalDate plus() method in Java with Examples In LocalDate class, there are two types of plus() method depending upon the parameters passed to it. plus(long amountToAdd, TemporalUnit unit) plus() method of a LocalDate class used to return a copy of this LocalDate with the specified amount of unit added to LocalDate.If it is not possible to add 2 min read LocalDate plusDays() Method in Java with Examples The plusDays() method of a LocalDate class in Java is used to add the number of specified day in this LocalDate and return a copy of LocalDate. For example, 2018-12-31 plus one day would result in 2019-01-01. This instance is immutable and unaffected by this method call. Syntax: public LocalDate plu 2 min read LocalDate plusMonths() method in Java with Examples The plusMonths() method of LocalDate class in Java is used to add the number of specified months in this LocalDate and return a copy of LocalDate. This method adds the months field in the following steps: Add the months to the month-of-year field. Check if the date after adding months is valid or no 2 min read Like