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