Close

Java Date Time - Duration.abs() Examples

Java Date Time Java Java API 


Class:

java.time.Duration

java.lang.Objectjava.lang.Objectjava.time.Durationjava.time.Durationjava.time.temporal.TemporalAmountTemporalAmountjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Method:

public Duration abs()

This method returns a copy of this Duration with a positive length.

Examples


package com.logicbig.example.duration;

import java.time.Duration;
import java.time.LocalTime;

public class AbsExample {

public static void main(String... args) {
Duration d = Duration.between(LocalTime.of(23, 30), LocalTime.of(12, 10));
System.out.println(d);

Duration d2 = d.abs();
System.out.println(d2);
}
}

Output

PT-11H-20M
PT11H20M




See Also