Java Date Time - YearMonth lengthOfYear() example








YearMonth lengthOfYear() returns the length of the year.

This returns the length of the year in days, either 365 or 366.

Syntax

lengthOfYear has the following syntax.

public int lengthOfYear()

Example

The following example shows how to use lengthOfYear.

import java.time.YearMonth;
/*w  w  w  . j a  v a2s.com*/
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.now();

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

  }
}

The code above generates the following result.