Java Date Time Java Java API
java.time.Period
public Period minus(TemporalAmount amountToSubtract)
This method returns a copy of this period with the specified period subtracted.
package com.logicbig.example.period;import java.time.Period;public class MinusExample { public static void main(String... args) { Period p = Period.of(100, 10, 20); System.out.println(p); Period p2 = Period.of(50, 8, 5); System.out.println(p2); Period p3 = p.minus(p2); System.out.println(p3); }}
P100Y10M20DP50Y8M5DP50Y2M15D
package com.logicbig.example.period;import java.time.Period;public class MinusExample2 { public static void main(String... args) { Period p = Period.of(100, 10, 20); System.out.println(p); Period p2 = Period.of(200, 80, 25); System.out.println(p2); Period p3 = p.minus(p2); System.out.println(p3); }}
P100Y10M20DP200Y80M25DP-100Y-70M-5D