Duration isNegative() example
Description
Duration isNegative()
checks if this duration is negative,
excluding zero.
A Duration can be positive, zero or negative.
Syntax
isNegative
has the following syntax.
public boolean isNegative()
Example
The following example shows how to use isNegative
.
import java.time.Duration;
import java.time.LocalTime;
//from w ww . j a v a 2s . c o m
public class Main {
public static void main(String[] args) {
Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
System.out.println(duration.isNegative());
duration = Duration.between(LocalTime.NOON,LocalTime.MIDNIGHT);
System.out.println(duration.isNegative());
}
}
The code above generates the following result.