In Java, LocalDateTime.parse(text) reads a LocalDateTime from a String written in the standard ISO form, such as 2026-03-15T10:30:45. The letter T separates the date from the time.
For any other text format, pass a DateTimeFormatter as the second argument, such as DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm").
A static method of java.time.LocalDateTime (since Java 8): call it on the class, as LocalDateTime.parse(), with no object needed. Add import java.time.LocalDateTime; at the top of your file.
Syntax
Pass the text, and a formatter if the text is not in ISO form.
Java
LocalDateTime a = LocalDateTime.parse("2026-03-15T10:30:45"); // ISO form
LocalDateTime b = LocalDateTime.parse("2026-03-15T10:30"); // seconds are optional
DateTimeFormatter f = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
LocalDateTime c = LocalDateTime.parse("15/03/2026 10:30", f); // 2026-03-15T10:30
Call
What it does
LocalDateTime.parse(text)
Reads ISO text such as 2026-03-15T10:30.
LocalDateTime.parse(text, formatter)
Reads text in the format described by the formatter.
dt.format(formatter)
The reverse: turns a date-time into text.
LocalDate.parse(text)
Reads only a date such as 2026-03-15.
The text must match the format exactly. Extra spaces, a space instead of T, or a missing time all fail.
Library declarations
Java
// java.time.LocalDateTime
public static LocalDateTime parse(CharSequence text)
public static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter)
Parameters
Parameter
Description
text (CharSequence)
The text to read, such as a String.
formatter (DateTimeFormatter)
Optional. Describes the format of the text. Without it, ISO format is used.