Close

Java Date Time - YearMonth.lengthOfYear() Examples

Java Date Time Java Java API 


Class:

java.time.YearMonth

java.lang.Objectjava.lang.Objectjava.time.YearMonthjava.time.YearMonthjava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Method:

public int lengthOfYear()

Returns the length of the year of this YearMonth object, either 365 or 366, depending on the leap year.


Examples


package com.logicbig.example.yearmonth;

import java.time.YearMonth;

public class LengthOfYearExample {

public static void main(String... args) {
YearMonth y = YearMonth.of(2010, 11);
System.out.println(y);

int l = y.lengthOfYear();
System.out.println(l);

YearMonth y2 = YearMonth.of(2020, 11);
System.out.println(y2);

int l2 = y2.lengthOfYear();
System.out.println(l2);
}
}

Output

2010-11
365
2020-11
366




See Also