This method adjusts the specified temporal object to have the same time fields as this object
package com.logicbig.example.localtime;
import java.time.*;
import java.time.temporal.Temporal;
public class AdjustIntoExample {
public static void main (String... args) {
LocalTime d = LocalTime.of(20, 30, 10);
Temporal t = d.adjustInto(
LocalDateTime.of(2015, 10, 2, 20, 50));
System.out.println(t);
t = d.adjustInto(
LocalTime.of(2, 20, 50, 100000));
System.out.println(t);
t = d.adjustInto(
ZonedDateTime.of(2015, 10, 2,
2, 20, 30, 100000,
ZoneId.systemDefault()));
System.out.println(t);
}
}
Output
2015-10-02T20:30:10
20:30:10
2015-10-02T20:30:10-05:00[America/Chicago]
package com.logicbig.example.localtime;
import java.time.*;
import java.time.temporal.Temporal;
public class AdjustIntoExample2 {
public static void main (String... args) {
LocalTime d = LocalTime.of(20, 30, 10);
Temporal t = d.adjustInto(
LocalDate.of(2015, 10, 2));
System.out.println(t);
}
}
Output
Caused by: java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: NanoOfDay
at java.time.LocalDate.with(LocalDate.java:1039)
at java.time.LocalDate.with(LocalDate.java:137)
at java.time.LocalTime.adjustInto(LocalTime.java:1333)
at com.logicbig.example.localtime.AdjustIntoExample2.main(AdjustIntoExample2.java:16)
... 6 more