Duration negated() example

Description

Duration negated() returns a copy of this duration with the length negated.

For example, PT1.3S will be returned as PT-1.3S.

This instance is immutable and unaffected by this method call.

Syntax

negated has the following syntax.


public Duration negated()

Example

The following example shows how to use negated.


import java.time.Duration;
import java.time.LocalTime;
//from   w ww.j a  v  a 2s .  c om
public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
    System.out.println(duration.negated().getSeconds());

  }
}

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