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.
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.
public static Period of( int numberOfYears, int numberOfMonths, int numberOfDays)
Parameters: This method accepts following parameters:
- numberOfYears: This is used to represent the amount of years which may be negative.
- numberOfMonths: This is used to represent the amount of months which may be negative.
- numberOfDays: This is used to represent the amount of days which may be negative.
Returns: This function returns the period which is the Period object parsed with the given number of Years, Months, and Days.
Below is the implementation of Period.of() method:
1 Years 5 Months 21 Days
-2 Years 10 Months -11 Days