Checks if this duration is negative.
package com.logicbig.example.duration;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
public class IsNegativeExample {
public static void main(String... args) {
Duration d = Duration.between(LocalDate.now().atStartOfDay(), LocalDateTime.now());
System.out.println(d);
boolean b = d.isNegative();
System.out.println(b);
d = Duration.between(LocalDateTime.now(), LocalDate.now().atStartOfDay());
System.out.println(d);
b = d.isNegative();
System.out.println(b);
}
}
Output
PT15H59M22.459S
false
PT-15H-59M-22.461S
true