Period from() method in Java with Examples Last Updated : 27 Nov, 2018 Comments Improve Suggest changes Like Article Like Report 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 // 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); } } Output: P20Y13M17D Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Period.html#from-java.time.temporal.TemporalAmount- Comment More infoAdvertise with us Next Article Period from() method in Java with Examples B barykrg Follow Improve Article Tags : Misc Java Java-Functions Java-time package Java-Period +1 More Practice Tags : JavaMisc Similar Reads Period get() method in Java with Examples The get() method of Period class in Java is used to get the value of the requested unit(YEARS, MONTHS or DAYS) given in the argument from this Period. Syntax: public long get(TemporalUnit unit) Parameters: This method accepts a single parameter unit of type TemporalUnit which is the unit to get requ 2 min read Period of() method in Java with Examples The of() method of Period Class is used to obtain a period from given number of Years, Months, and Days as parameters. These parameters are accepted in the form of integers. This method returns a Period with the given number of years, months, and days. Syntax: public static Period of( int numberOfYe 2 min read Period plus() method in Java with Examples The plus() method of Period class in Java is used to add the given amount of period to the specified period. This functions operates separately on YEAR, MONTH and DAY. Note: Normalization is not performed. 12 months and 1 year are different. Syntax: public Period plus(TemporalAmount amountToAdd) Par 2 min read Period getYears() method in Java with Examples The getYears() method of Period in Java is used to get the amount of years of this period with which it is used. Note: 15 months is not equal to 1 years and 3 months. Syntax: public List getYears() Parameters: This method does not accepts any parameter. Returns: This method returns the amounts of ye 2 min read Period hashCode() method in Java with Examples The hashCode() method of Period class in Java is used to get the generated hashCode for this period. Syntax: public int hashCode() Parameters: This method does not accepts any parameter. Return Value: This method returns the hashCode generated for the given period. Below programs illustrate the hash 2 min read Like