This method adjusts the specified temporal object to have the same date and time fields as this object

package com.logicbig.example.localdatetime;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;
public class AdjustIntoExample {
public static void main (String... args) {
LocalDateTime d = LocalDateTime.of(2012, Month.APRIL, 10, 14, 30);
ZonedDateTime z = ZonedDateTime.of(LocalDateTime.now(),
ZoneId.of("America/New_York"));
Temporal t = d.adjustInto(z);
System.out.println(t);
//or alternatively
ZonedDateTime z2 = z.with(d);
System.out.println(z2);
}
}
Output
2012-04-10T14:30-04:00[America/New_York]
2012-04-10T14:30-04:00[America/New_York]

package com.logicbig.example.localdatetime;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;
public class AdjustIntoExample2 {
public static void main (String... args) {
LocalDateTime d = LocalDateTime.of(2012, Month.APRIL, 10, 14, 30);
ZonedDateTime z = ZonedDateTime.now();
Temporal t = d.adjustInto(z);
System.out.println(t);
}
}
Output
2012-04-10T14:30+08:00[America/Chicago]

package com.logicbig.example.localdatetime;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.YearMonth;
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;
public class AdjustIntoExample3 {
public static void main (String... args) {
LocalDateTime d = LocalDateTime.of(2012, Month.APRIL, 10, 14, 30);
YearMonth y = YearMonth.of(2015, Month.AUGUST);
Temporal t = d.adjustInto(y);
System.out.println(t);
}
}
Output
java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: EpochDay
at java.time.YearMonth.with (YearMonth.java:693)
at java.time.YearMonth.with (YearMonth.java:131)
at java.time.chrono.ChronoLocalDateTime.adjustInto (ChronoLocalDateTime.java:379)
at java.time.LocalDateTime.adjustInto (LocalDateTime.java:1629)
at com.logicbig.example.localdatetime.AdjustIntoExample3.main (AdjustIntoExample3.java:19)