Year length() method in Java with Examples
The length() method of Year class in Java is used to return the length of this year object’s value in number of days. There can be only two possible lengths of Year, 365(Non-leap years) and 366(Leap years).
Syntax:
public int length()
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 length() method of Year in Java:
Program 1:
// Program to illustrate the length() method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Create a Year object Year thisYear = Year.of(2016); // Print the length of this year in Number // of days, 366 in this case as 2016 is // a Leap Year System.out.println(thisYear.length()); } } |
366
Program 2:
// Program to illustrate the length() method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Create a Year object Year thisYear = Year.of(1990); // Print the length of this year in Number // of days, 365 in this case as 1990 is not // a Leap Year System.out.println(thisYear.length()); } } |
365
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#length–
Recommended Posts:
- Year of() method in Java with Examples
- Year from() Method in Java with Examples
- Year get() method in Java with Examples
- Year now() method in Java with examples
- Year until() Method in Java with Examples
- Year with() Method in Java with Examples
- Year minusYears() method in Java with Examples
- Year plusYears() Method in Java with Examples
- Year isBefore() method in Java with Examples
- Year isLeap() method in Java with Examples
- Year getLong() method in Java with Examples
- Year adjustInto() Method in Java with Examples
- Year plus(TemporalAmount) method in Java with Examples
- Year range() method in Java with Examples
- Year query() 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.



