Period subtractFrom(Temporal temporal) example

Description

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.c  om*/
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.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset