Month length(boolean leapYear) example

Description

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;
// www .jav  a 2  s  . com
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.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset