Java Date Time Java Java API
java.time.Period
public Period minusYears(long yearsToSubtract)
This method returns a copy of this period with the specified years subtracted.
package com.logicbig.example.period;import java.time.Period;public class MinusYearsExample { public static void main(String... args) { Period p = Period.of(100, 10, 20); System.out.println(p); Period p2 = p.minusYears(20); System.out.println(p2); Period p3 = p.minusYears(-20); System.out.println(p3); }}
P100Y10M20DP80Y10M20DP120Y10M20D