Java Date Time - Period subtractFrom(Temporal temporal) example








Period subtractFrom(Temporal temporal) subtracts this period 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.LocalDate;
import java.time.Period;
import java.time.temporal.Temporal;
/*from w w  w  . ja v  a2s.com*/
public class Main {
  public static void main(String[] args) {
    Period p = Period.ofDays(12);
    
    Temporal l = p.subtractFrom(LocalDate.now());
    System.out.println(l);

  }
}

The code above generates the following result.