The lengthOfYear() method of YearMonth class in Java is used to return the length of year of this year-month object’s value in number of days. The value of the length of a year is either 365 or 366 based on whether the Year is leap or not.
Syntax:
public int lengthOfYear()
Parameter: This method does not accepts any parameter.
Return Value: It returns an integer value denoting the length of year in number of days.
Below programs illustrate the lengthOfYear() 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.lengthOfYear());
}
}
|
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.lengthOfYear());
}
}
|
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/YearMonth.html#lengthOfYear–
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
05 May, 2020
Like Article
Save Article