Thursday, October 23, 2025
HomeLanguagesJavaJapaneseDate lengthOfYear() method in Java with Examples

JapaneseDate lengthOfYear() method in Java with Examples

The lengthOfYear() method of java.time.chrono.JapaneseDate class is used to get the no of days present in a year represented by a particular japanese 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 japanese 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
            // japaneseDate Object
            JapaneseDate hidate
                = JapaneseDate.of(2006, 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: 365

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
            // japaneseDate Object
            JapaneseDate hidate
                = JapaneseDate.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: 366

Reference: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/JapaneseDate.html#lengthOfYear–

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS