Sunday, November 23, 2025
HomeLanguagesJavaChronoLocalDate lengthOfMonth() method in Java with Examples

ChronoLocalDate lengthOfMonth() method in Java with Examples

The lengthOfMonth() method of ChronoLocalDate interface in Java returns the length of the month represented by this date.

Syntax:

public int lengthOfMonth()

Parameter: This method does not accept parameters.

Return Value: The function returns the length of the month in days.

Below programs illustrate the lengthOfMonth() method of ChronoLocalDate in Java:

Program 1:




// Program to illustrate the lengthOfMonth() method
  
import java.util.*;
import java.time.*;
import java.time.chrono.*;
  
public class GfG {
    public static void main(String[] args)
    {
        // Parse the date
        ChronoLocalDate dt1
            = LocalDate.parse("2018-11-27");
  
        // Get the length of the month
        System.out.println(dt1.lengthOfMonth());
    }
}


Output:

30

Program 2:




// Program to illustrate the lengthOfMonth() method
  
import java.util.*;
import java.time.*;
import java.time.chrono.*;
  
public class GfG {
    public static void main(String[] args)
    {
        // Parses the date
        ChronoLocalDate dt1
            = LocalDate.parse("2018-01-27");
  
        // Get the length of the month
        System.out.println(dt1.lengthOfMonth());
    }
}


Output:

31

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

RELATED ARTICLES

Most Popular

Dominic
32410 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6785 POSTS0 COMMENTS
Nicole Veronica
11932 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12000 POSTS0 COMMENTS
Shaida Kate Naidoo
6909 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6865 POSTS0 COMMENTS
Umr Jansen
6852 POSTS0 COMMENTS