Java Date Time Java Java API
java.time.Period
public Period negated()
This method returns a new instance of Period with each part of this period negated.
package com.logicbig.example.period;import java.time.Period;public class NegatedExample { public static void main(String... args) { Period p = Period.of(100, 10, 20); System.out.println(p); Period p2 = p.negated(); System.out.println(p2); }}
P100Y10M20DP-100Y-10M-20D
package com.logicbig.example.period;import java.time.Period;public class NegatedExample2 { public static void main(String... args) { Period p = Period.of(-100, -10, 20); System.out.println(p); Period p2 = p.negated(); System.out.println(p2); }}
P-100Y-10M20DP100Y10M-20D