The from() method of Period class in Java is used to get an instance of Period from given temporal amount.

This function obtains a period based on the amount given in argument. A TemporalAmount represents an amount of time, which may be date-based or time-based.

**Syntax:**

public static Period from(TemporalAmount amount)

**Parameters:** This method accepts a single parameter *amount*. This amount is the amount that we need to convert into period.

**Return Value:** This function returns the period equivalent to the given amount.

**Exceptions:**

**DateTimeException**– It throws DateTimeException, if unable to convert to a Period.**ArithmeticException**– It throws ArithmeticException, if the amount of years, months or days exceeds an int.

Below program illustrate the above method:

`// Java code to show the function from() ` `// which represents the period of given amount ` `import` `java.time.Period; ` ` ` `public` `class` `PeriodClassGfG { ` ` ` ` ` `// Function to convert given amount to period ` ` ` `static` `void` `convertToPeriod(` `int` `year, ` `int` `months, ` `int` `days) ` ` ` `{ ` ` ` `Period period = Period.from(Period.of(year, months, days)); ` ` ` ` ` `System.out.println(period); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` ` ` `int` `year = ` `20` `, months = ` `13` `, days = ` `17` `; ` ` ` `Period period = Period.from(Period.of(year, months, days)); ` ` ` ` ` `convertToPeriod(year, months, days); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

**Output:**

P20Y13M17D

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Period plus() method in Java with Examples
- Period between() method in Java with Examples
- Period of() method in Java with Examples
- Period get() method in Java with Examples
- Period minus() method in Java with Examples
- Period isZero() method in Java with Examples
- Period getYears() method in Java with Examples
- Period minusMonths() method in Java with Examples
- Period minusYears() method in Java with Examples
- Period multipliedBy() method in Java with Examples
- Period getDays() method in Java with Examples
- Period equals() method in Java with Examples
- Period getMonths() method in Java with Examples
- Period negated() method in Java with Examples
- Period normalized() method in Java with Examples
- Period plusYears() method in Java with Examples
- Period isNegative() method in Java with Examples
- Period hashCode() method in Java with Examples
- Period getUnits() method in Java with Examples
- Period plusDays() method in Java with Examples

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.