Wednesday, July 3, 2024
HomeLanguagesJavaHijrahDate lengthOfYear() method in Java with Example

HijrahDate lengthOfYear() method in Java with Example

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




// Java program to demonstrate
// lengthOfYear() method
  
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 {
            // Creating and initializing
            // HijrahDate Object
            HijrahDate hidate
                = HijrahDate.of(1345, 06, 23);
  
            // Getting length of a year
            // by using lengthOfYear() method
            int length = hidate.lengthOfYear();
  
            // Display the result
            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




// Java program to demonstrate
// lengthOfYear() method
  
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 {
            // Creating and initializing
            // HijrahDate Object
            HijrahDate hidate = HijrahDate.now();
  
            // Getting length of a year
            // by using lengthOfYear() method
            int length = hidate.lengthOfYear();
  
            // Display the result
            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–

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments