Duration abs() example
Description
Duration abs()
returns a copy of this duration with a positive length.
For example, PT-1.3S will be returned as PT1.3S.
Syntax
abs
has the following syntax.
public Duration abs()
Example
The following example shows how to use abs
.
import java.time.Duration;
import java.time.LocalTime;
/*w ww . j av a 2 s . com*/
public class Main {
public static void main(String[] args) {
Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
System.out.println(duration.abs());
}
}
The code above generates the following result.