YearMonth lengthOfMonth() example

Description

YearMonth lengthOfMonth() returns the length of the month, taking account of the year.

This returns the length of the month in days. For example, a date in January would return 31.

Syntax

lengthOfMonth has the following syntax.


public int lengthOfMonth()

Example

The following example shows how to use lengthOfMonth.


import java.time.YearMonth;
/*from w  w  w . j  av  a2  s . c  o m*/
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.now();

    System.out.println(y.lengthOfMonth());

  }
}

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