The lengthOfYear() method of java.time.chrono.HijrahDate class is used to get the no of days present in a year represented by a particular hijrah date.
Syntax:
public int lengthOfYear()
Parameter: This method does not accept any argument as a parameter.
Return Value: This method returns the number of days present as an integer value in a year represented by a particular hijrah date.
Below are the examples to illustrate the lengthOfYear() method:
Example 1:
Java
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] argv)
{
try {
HijrahDate hidate
= HijrahDate.of( 1345 , 06 , 23 );
int length = hidate.lengthOfYear();
System.out.println( "no of day present: "
+ length);
}
catch (DateTimeException e) {
System.out.println( "passed parameter can"
+ " not form a date" );
System.out.println( "Exception thrown: "
+ e);
}
}
}
|
Output:
no of day present: 354
Example 2:
Java
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] argv)
{
try {
HijrahDate hidate = HijrahDate.now();
int length = hidate.lengthOfYear();
System.out.println( "no of day present: "
+ length);
}
catch (DateTimeException e) {
System.out.println( "passed parameter can"
+ " not form a date" );
System.out.println( "Exception thrown: "
+ e);
}
}
}
|
Output:
no of day present: 355
Reference: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/HijrahDate.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 :
27 Feb, 2020
Like Article
Save Article