Home Java LocalDateTime Methods from() Java LocalDateTime from() Method Definition In Java, LocalDateTime.from(temporal) converts another date-time object into a LocalDateTime. It works for any object that holds both a date and a time, such as a ZonedDateTime or an OffsetDateTime.
The zone or offset is simply dropped. You keep the date and the clock time as they were shown. If the object has no date or no time, the method throws an exception.
A static method of java.time.LocalDateTime (since Java 8): call it on the class, as LocalDateTime.from(), with no object needed. Add import java.time.LocalDateTime; at the top of your file.
Syntax Pass the object to convert. The method is also handy as a method reference, LocalDateTime::from.
ZonedDateTime zoned = ZonedDateTime.of(LocalDateTime.of(2026, 3, 15, 10, 30), ZoneId.of("Asia/Kolkata"));
LocalDateTime dt = LocalDateTime.from(zoned); // 2026-03-15T10:30 Call What it does LocalDateTime.from(zdt)Drops the zone from a ZonedDateTime. LocalDateTime.from(odt)Drops the offset from an OffsetDateTime. zdt.toLocalDateTime()The same conversion written as an instance method. formatter.parse(text, LocalDateTime::from)Parses text and converts it in one step.
If you already know the exact type, zdt.toLocalDateTime() is shorter. from() is most useful when the type is general, as in TemporalAccessor.
Library declarations // java.time.LocalDateTime
public static LocalDateTime from(TemporalAccessor temporal) Parameters Parameter Description temporal (TemporalAccessor)The object to convert. It must hold both a date and a time.
Return Value Return Value Description LocalDateTimeThe date and time taken from the object, without any zone or offset.
Important
Dropping the zone changes the meaning: 10:30 in Kolkata and 10:30 in Tokyo become the same LocalDateTime, although they are different moments in time. A LocalDate, a LocalTime, or an Instant cannot be converted, because each one misses a part, and the method throws a DateTimeException.
Compare with Similar Methods Other ways to get a LocalDateTime:
Java Examples 1. From a zoned date-time 2. Offset and method reference 3. Missing parts Example 1 — Drop the Zone from a ZonedDateTime Convert a date-time with a zone into a plain LocalDateTime.
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
public class LdtFromDemo {
public static void main(String[] args) {
ZonedDateTime zoned = ZonedDateTime.of(LocalDateTime.of(2026, 3, 15, 10, 30), ZoneId.of("Asia/Kolkata"));
LocalDateTime plain = LocalDateTime.from(zoned);
System.out.println("zoned: " + zoned);
System.out.println("plain: " + plain);
}
} zoned: 2026-03-15T10:30+05:30[Asia/Kolkata]
plain: 2026-03-15T10:30 How It Works A zoned date-time. It holds the date, the time, and the zone Asia/Kolkata.Convert it. LocalDateTime.from(zoned) keeps the date and the clock time.The zone is dropped. The first line shows the offset and the zone name in brackets. The second line shows only the date and time.Example 2 — Use from with OffsetDateTime and as a Method Reference Convert an OffsetDateTime, and then parse text and convert it with LocalDateTime::from.
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
public class LdtFromOffset {
public static void main(String[] args) {
OffsetDateTime offset = OffsetDateTime.of(LocalDateTime.of(2026, 3, 15, 10, 30), ZoneOffset.ofHours(2));
System.out.println("from offset: " + LocalDateTime.from(offset));
LocalDateTime parsed = DateTimeFormatter.ISO_LOCAL_DATE_TIME.parse("2026-03-15T08:15:00", LocalDateTime::from);
System.out.println("from parsing: " + parsed);
}
} from offset: 2026-03-15T10:30
from parsing: 2026-03-15T08:15 How It Works An offset date-time. It holds the date, the time, and the offset +02:00.The offset is dropped. The first result is 10:30 with no offset.A method reference. LocalDateTime::from matches what parse(text, query) expects, so the formatter gives you a LocalDateTime directly.The parsed result. The second line shows 08:15, with the zero seconds hidden.Example 3 — See What Cannot Be Converted Try to convert a LocalDate, a LocalTime, and an Instant, which each miss a part.
import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
public class LdtFromFails {
public static void main(String[] args) {
try {
LocalDateTime.from(LocalDate.of(2026, 3, 15));
} catch (DateTimeException e) {
System.out.println("LocalDate -> DateTimeException (no time)");
}
try {
LocalDateTime.from(LocalTime.of(10, 30));
} catch (DateTimeException e) {
System.out.println("LocalTime -> DateTimeException (no date)");
}
try {
LocalDateTime.from(Instant.parse("2026-03-15T10:30:00Z"));
} catch (DateTimeException e) {
System.out.println("Instant -> DateTimeException (no zone)");
}
}
} LocalDate -> DateTimeException (no time)
LocalTime -> DateTimeException (no date)
Instant -> DateTimeException (no zone) How It Works A LocalDate has no time. The method cannot make up the hour and minute, so it throws a DateTimeException.A LocalTime has no date. It fails the same way.An Instant has no zone. It is only a moment on the timeline, so Java does not know which wall clock to use. Use ofInstant() with a zone instead.Frequently Asked Questions How do I convert a ZonedDateTime to a LocalDateTime in Java? Use zdt.toLocalDateTime() or LocalDateTime.from(zdt). Both keep the date and the clock time and drop the zone.
Why can't I convert an Instant with LocalDateTime.from()? An Instant has no zone, so Java cannot work out the wall-clock time. Use LocalDateTime.ofInstant(instant, zone).
Does LocalDateTime.from() change the time? No. It keeps the clock time that the object shows, and only removes the zone or offset.
What does LocalDateTime::from mean? It is a method reference to this method. You can pass it where a TemporalQuery is expected, such as formatter.parse(text, LocalDateTime::from).
What is the difference between from() and of()? from() converts an existing date-time object. of() builds a new one from numbers or from a LocalDate and a LocalTime.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
12 people found this page helpful
Helpful Share Copy link Suggestion