Java Date Time - Duration minusSeconds(long secondsToSubtract) example








Duration minusSeconds(long secondsToSubtract) returns a copy of this duration with the specified duration in seconds subtracted.

Syntax

minusSeconds has the following syntax.

public Duration minusSeconds(long secondsToSubtract)

Example

The following example shows how to use minusSeconds.

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

  }
}

The code above generates the following result.