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);
}
}
Output
P100Y10M20D
P-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);
}
}
Output
P-100Y-10M20D
P100Y10M-20D