Java Date Time - Period addTo(Temporal temporal) example








Period addTo(Temporal temporal) adds this period to the specified temporal object.

Syntax

addTo has the following syntax.

public Temporal addTo(Temporal temporal)

Example

The following example shows how to use addTo.

import java.time.LocalDate;
import java.time.Period;
import java.time.temporal.Temporal;
/*from w  ww.  j av  a  2  s.c  om*/
public class Main {
  public static void main(String[] args) {
    Period p = Period.ofDays(12);
    
    Temporal l = p.addTo(LocalDate.now());
    System.out.println(l);

  }
}

The code above generates the following result.