Java Date Time - Duration minusDays(long daysToSubtract) example








Duration minusDays(long daysToSubtract) returns a copy of this duration with the specified duration in standard 24 hour days subtracted.

Syntax

minusDays has the following syntax.

public Duration minusDays(long daysToSubtract)

Example

The following example shows how to use minusDays.

import java.time.Duration;
import java.time.LocalTime;
/*  w ww.j  a v  a2s  .  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.minusDays(3);
    System.out.println(duration.getSeconds());

  }
}

The code above generates the following result.