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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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());
    }
}

chevron_right


Output:

30

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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());
    }
}

chevron_right


Output:

31

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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.