Period from() method in Java with Examples
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.
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.
- 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:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.