Period getMonths() method in Java with Examples
The getMonths() method of Period class in Java is used to get the number of months in this current period with which it is used.
public int getMonths()
Parameters: This method does not accepts any parameter.
Return Value: This function returns the number of months in the given period.
Note: There is difference between 12 months and 1 year.
Below programs illustrate the above method:
Program 2: This will not convert 13 months to year.
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.