Java Date Time - YearMonth plus(TemporalAmount amountToAdd) example








YearMonth plus(TemporalAmount amountToAdd) returns a copy of this year-month with the specified amount added.

Syntax

plus has the following syntax.

public YearMonth plus(TemporalAmount amountToAdd)

Example

The following example shows how to use plus.

import java.time.Period;
import java.time.YearMonth;
//  w ww.j a  v a2 s  . c o m
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.now();
    YearMonth s = y.plus(Period.ofYears(3));
    System.out.println(s);

  }
}

The code above generates the following result.