Java Date Time Java Java API
java.time.Period
public boolean isNegative()
package com.logicbig.example.period;import java.time.Period;public class IsNegativeExample { public static void main(String... args) { Period p = Period.of(100, 10, 20); System.out.println(p); boolean b = p.isNegative(); System.out.println(b); }}
P100Y10M20Dfalse
package com.logicbig.example.period;import java.time.Period;public class IsNegativeExample2 { public static void main(String... args) { Period p = Period.of(-100, 10, 20); System.out.println(p); boolean b = p.isNegative(); System.out.println(b); }}
P-100Y10M20Dtrue
package com.logicbig.example.period;import java.time.Period;public class IsNegativeExample3 { public static void main(String... args) { Period p = Period.of(100, 10, 20); System.out.println(p); boolean b = p.isNegative(); System.out.println(b); Period p2 = p.negated(); boolean b2 = p2.isNegative(); System.out.println(b2); }}
P100Y10M20Dfalsetrue