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.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset