Duration minus(Duration duration) example

Description

Duration minus(Duration duration) returns a copy of this duration with the specified duration subtracted.

Syntax

minus has the following syntax.


public Duration minus(Duration duration)

Example

The following example shows how to use minus.


import java.time.Duration;
import java.time.LocalTime;
/* w w w  .  j  a v  a2  s.com*/
public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
    System.out.println(duration.getSeconds());
    duration = duration.minus(duration);
    System.out.println(duration.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