Close

Java Date Time - YearMonth.withYear() 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 YearMonth withYear(int year)

Returns a copy of this YearMonth with year field replaced with the specified year value.


Examples


package com.logicbig.example.yearmonth;

import java.time.YearMonth;

public class WithYearExample {

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

YearMonth y2 = y.withYear(1980);
System.out.println(y2);
}
}

Output

2010-11
1980-11




See Also