Close

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

Returns a copy of this YearMonth with the month-of-year replaced by the the specified month.


Examples


package com.logicbig.example.yearmonth;

import java.time.YearMonth;

public class WithMonthExample {

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

YearMonth y2 = y.withMonth(12);
System.out.println(y2);
}
}

Output

2010-11
2010-12




See Also