Close

Java Date Time - YearMonth.getYear() 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 getYear()

Returns the year field of this YearMonth object


Examples


package com.logicbig.example.yearmonth;

import java.time.YearMonth;

public class GetYearExample {

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

int year = y.getYear();
System.out.println(year);
}
}

Output

2010-11
2010




See Also