Java Date Time - YearMonth minusMonths(long monthsToSubtract) example








YearMonth minusMonths(long monthsToSubtract) returns a copy of this year-month with the specified period in months subtracted.

Syntax

minusMonths has the following syntax.

public YearMonth minusMonths(long monthsToSubtract)

Example

The following example shows how to use minusMonths.

import java.time.YearMonth;
/*  w  w  w.  j  a v  a 2  s  . c  om*/
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.now();
    YearMonth s = y.minusMonths(12);
    System.out.println(s);

  }
}

The code above generates the following result.