Java Date Time - Duration subtractFrom(Temporal temporal) example








Duration subtractFrom(Temporal temporal) subtracts this duration from the specified temporal object.

Syntax

subtractFrom has the following syntax.

public Temporal subtractFrom(Temporal temporal)

Example

The following example shows how to use subtractFrom.

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.temporal.Temporal;
//www  .j  av a  2s.  c  o  m
public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.ofDays(2);
    Temporal l = duration.subtractFrom(LocalDateTime.now());
    
    System.out.println(l);
  }
}

The code above generates the following result.