YearMonth lengthOfMonth method() in Java
Last Updated :
30 Nov, 2018
The lengthOfMonth() method of YearMonth class in Java is used to return the length of month of this year-month object’s value in number of days. The value of length of month is in the range of 1 to 31. This method also take cares of leap years.
Syntax:
public int lengthOfMonth()
Parameter: This method does not accepts any parameter.
Return Value: It returns an integer value denoting the length of month in number of days.
Below programs illustrate the lengthOfMonth() method of YearMonth in Java:
Program 1:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
YearMonth yearMonth = YearMonth.of( 2016 , 2 );
System.out.println(yearMonth.lengthOfMonth());
}
}
|
Program 2:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
YearMonth yearMonth = YearMonth.of( 1990 , 2 );
System.out.println(yearMonth.lengthOfMonth());
}
}
|
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/YearMonth.html#lengthOfMonth–
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...