Java Date Time - YearMonth plusYears(long yearsToAdd) example








YearMonth plusYears(long yearsToAdd) returns a copy of this year-month with the specified period in years added.

Syntax

plusYears has the following syntax.

public YearMonth plusYears(long yearsToAdd)

Example

The following example shows how to use plusYears.

import java.time.YearMonth;
/*from   w  ww.  ja v a2s .  c om*/
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.now();
    YearMonth s = y.plusYears(3);
    System.out.println(s);

  }
}

The code above generates the following result.