YearMonth lengthOfYear() method in Java with Examples
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 length of 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:
// Program to illustrate the lengthOfYear() method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Create YearMonth object YearMonth yearMonth = YearMonth.of(2016, 2); // Print the length of year in Number // of days, 366 in this case as 2016 is // a Leap Year System.out.println(yearMonth.lengthOfYear()); } } |
Program 2:
// Program to illustrate the lengthOfYear() method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Create YearMonth object YearMonth yearMonth = YearMonth.of(1990, 2); // Print the length of year in Number // of days, 365 in this case as 1990 is // not a Leap Year System.out.println(yearMonth.lengthOfYear()); } } |
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/YearMonth.html#lengthOfYear–
Recommended Posts:
- LocalDate lengthOfYear() method in Java with Examples
- ChronoLocalDate lengthOfYear() method in Java with Examples
- YearMonth with() Method in Java with Examples
- YearMonth until() Method in Java with Examples
- YearMonth isAfter() method in Java with Examples
- YearMonth withYear() method in Java with Examples
- YearMonth plus(TemporalAmount) method in Java with Examples
- YearMonth range() method in Java with Examples
- YearMonth withMonth() method in Java with Examples
- YearMonth isValidDay() method in Java with Examples
- YearMonth isLeapYear() method in Java with Examples
- YearMonth isBefore() method in Java with Examples
- YearMonth query() Method in Java with Examples
- YearMonth plus(long,unit) method in Java with Examples
- YearMonth isSupported(TemporalField) method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



