Year length() method in Java with Examples
Last Updated :
27 Nov, 2018
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:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
Year thisYear = Year.of( 2016 );
System.out.println(thisYear.length());
}
}
|
Program 2:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
Year thisYear = Year.of( 1990 );
System.out.println(thisYear.length());
}
}
|
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#length–
Share your thoughts in the comments
Please Login to comment...