Close

Java Date Time - YearMonth.adjustInto() 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 Temporal adjustInto(Temporal temporal)

This method adjusts and returns the copy of the specified temporal object having this year-month fields.


Examples


package com.logicbig.example.yearmonth;

import java.time.*;
import java.time.temporal.Temporal;

public class AdjustIntoExample {

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

adjust(y, LocalDate.now());
adjust(y, LocalDateTime.now());
adjust(y, OffsetDateTime.now());
adjust(y, ZonedDateTime.now());
adjust(y, YearMonth.now());
}

private static void adjust(YearMonth y, Temporal t) {
Temporal t2 = y.adjustInto(t);
System.out.printf("%15s > %s > %s%n",
t.getClass().getSimpleName(),
t, t2);
}
}

Output

2010-11
LocalDate > 2017-05-01 > 2010-11-01
LocalDateTime > 2017-05-01T15:52:34.786 > 2010-11-01T15:52:34.786
OffsetDateTime > 2017-05-01T15:52:34.787-05:00 > 2010-11-01T15:52:34.787-05:00
ZonedDateTime > 2017-05-01T15:52:34.787-05:00[America/Chicago] > 2010-11-01T15:52:34.787-05:00[America/Chicago]
YearMonth > 2017-05 > 2010-11




See Also