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.
public long get(TemporalUnit unit)
Parameters: This method accepts a single parameter unit of type TemporalUnit which is the unit to get required unit.
Return Value: This function returns the long value of the requested unit.
- DateTimeException – This method throws DateTimeException, if the unit in argument is not supported.
- UnsupportedTemporalTypeException – This method throws UnsupportedTemporalTypeException if the unit given in argument is not supported.
Below programs 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.