Saturday, October 18, 2025
HomeLanguagesJavaLocalDate lengthOfMonth() method in Java with Examples

LocalDate lengthOfMonth() method in Java with Examples

The lengthOfMonth() method of LocalDate class 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 LocalDate in Java:

Program 1:




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


Output:

30

Program 2:




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


Output:

31

Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDate.html#lengthOfMonth()

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
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