Java Date Time - Period from(TemporalAmount amount) example








Period from(TemporalAmount amount) creates an instance of Period from a temporal amount.

Syntax

from has the following syntax.

public static Period from(TemporalAmount amount)

Example

The following example shows how to use from.

import java.time.Period;
/*www . ja  v  a  2  s  . com*/
public class Main {
  public static void main(String[] args) {
    
    Period p = Period.from(Period.ofMonths(12));

    System.out.println(p.toString());

  }
}

The code above generates the following result.