Period from(TemporalAmount amount) example

Description

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;
//from  w w w  . j  a v  a2  s. co m
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.





















Home »
  Java Date Time »
    java.time Reference »




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