Java Date Time - Duration minusMinutes(long minutesToSubtract) example








Duration minusMinutes(long minutesToSubtract) returns a copy of this duration with the specified duration in minutes subtracted.

Syntax

minusMinutes has the following syntax.

public Duration minusMinutes(long minutesToSubtract)

Example

The following example shows how to use minusMinutes.

import java.time.Duration;
import java.time.LocalTime;
/*from w w  w  .  j ava2 s.co m*/
public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
    System.out.println(duration.getSeconds());
    duration = duration.minusMinutes(300);
    System.out.println(duration.getSeconds());

  }
}

The code above generates the following result.