Close

Java Date Time - LocalTime.adjustInto() Examples

[Last Updated: Nov 8, 2025]

Java Date Time Java Java API 


Class:

java.time.LocalTime

java.lang.Objectjava.lang.Objectjava.time.LocalTimejava.time.LocalTimejava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Method:

public Temporal adjustInto(Temporal temporal)

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

This method will throw UnsupportedTemporalTypeException if the provided temporal object does not support the LocalTime fields.



Examples


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+08: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

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)




See Also