Java Date Time - Month length(boolean leapYear) example








Month length(boolean leapYear) gets the length of this month in days.

February has 28 days in a standard year and 29 days in a leap year. April, June, September and November have 30 days. All other months have 31 days.

Syntax

length has the following syntax.

public int length(boolean leapYear)

Example

The following example shows how to use length.

import java.time.LocalDate;
import java.time.Month;
/*from www. ja v  a2 s.c om*/
public class Main {
  public static void main(String[] args) {
    Month m = Month.from(LocalDate.now());
    
    System.out.println(m.length(true));

  }
}

The code above generates the following result.