Java Date Time - Period minusYears(long yearsToSubtract) example








Period minusYears(long yearsToSubtract) returns a copy of this period with the specified years subtracted.

Syntax

minusYears has the following syntax.

public Period minusYears(long yearsToSubtract)

Example

The following example shows how to use minusYears.

import java.time.Period;
/* ww w  . j av  a  2s  . c  o m*/
public class Main {
  public static void main(String[] args) {
    Period p = Period.ofMonths(1);
    
    Period l = p.minusYears(10);
    System.out.println(l);

  }
}

The code above generates the following result.