Java: DateTimeParseException: Text could not be parsed
The formatter pattern and the input disagree. Check the index in the message, the locale, and whether the text needs a ZonedDateTime instead.

Introduction & Quick Summary
Parsing a date from a config file, a CSV column or an API response throws:
java.time.format.DateTimeParseException: Text '2026-11-28 07:00' could not be parsed
at index 10
at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2106)Quick answer: DateTimeFormatter parses with an exact pattern, and the text does not match it at the reported index. index 10 in 2026-11-28 07:00 is the space where the pattern probably expects T. The formatter never guesses the missing pieces; either the pattern must describe the input, or the input must be normalised first.
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
LocalDateTime dt = LocalDateTime.parse("2026-11-28 07:00", fmt); // ok
LocalDateTime iso = LocalDateTime.parse("2026-11-28T07:00:00"); // default ISO_LOCAL_DATE_TIMEThe same exception has three common shapes: a pattern mismatch (index 10), a value out of range (Invalid date 'FEBRUARY 30'), and a missing time zone for a type that needs one. The rest of this guide shows how to read the index, which type to parse into, and how locale changes the result.
Core Mechanics, Signatures & Reproducible Setup
DateTimeFormatter has predefined constants and custom patterns. Parsing produces a TemporalAccessor, and the type you ask for decides which fields must be present.
import java.time.*;
import java.time.format.*;
DateTimeFormatter iso = DateTimeFormatter.ISO_LOCAL_DATE_TIME; // 2026-11-28T07:00:00
DateTimeFormatter spaced = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
ZonedDateTime zoned = ZonedDateTime.parse(
"2026-11-28T07:00:00+09:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME);
Instant instant = Instant.from(DateTimeFormatter.ISO_INSTANT.parse("2026-11-28T07:00:00Z"));
LocalDate date = LocalDate.parse("2026-11-28", DateTimeFormatter.ISO_LOCAL_DATE);Pattern letters are case sensitive and mean different things: yyyy is year-of-era, uuuu is proleptic year, MM is month, mm is minute, HH is hour 0-23 and hh is hour 1-12. A pattern written with mm where MM belongs parses January as minutes and fails at the month, and YYYY (week-based year) produces wrong dates around New Year.
// wrong: minutes where month belongs
DateTimeFormatter.ofPattern("yyyy-mm-dd") // fails at index 5
// right
DateTimeFormatter.ofPattern("uuuu-MM-dd")A reproducible test for the error text:
public class Parse {
public static void main(String[] args) {
var f = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
try {
LocalDateTime.parse("2026-11-28 07:00:00", f);
} catch (DateTimeParseException e) {
System.out.println(e.getMessage());
System.out.println("parsed up to: " + e.getParsedString());
System.out.println("error index: " + e.getErrorIndex());
}
}
}getErrorIndex() and getParsedString() are the accessors worth knowing: the first points at the exact character, the second returns the input.
Key Comparison Table
| Target type | Requires | Example input | Fails when |
|---|---|---|---|
LocalDate | date fields only | 2026-11-28 | time zone text present |
LocalDateTime | date and time | 2026-11-28T07:00 | offset present with strict mode |
OffsetDateTime | date, time, offset | 2026-11-28T07:00+09:00 | offset missing |
ZonedDateTime | date, time, zone or offset | 2026-11-28T07:00+09:00[Asia/Seoul] | zone missing |
Instant | instant with offset or Z | 2026-11-28T07:00:00Z | local time only |
| Symptom | Meaning | Fix |
|---|---|---|
could not be parsed at index 10 | character 10 does not match | align pattern with input |
could not be parsed at index 0 | input empty or wrong type | validate before parsing |
Invalid date 'FEBRUARY 30' | value out of range | ResolverStyle or validation |
Unable to obtain LocalDateTime | parsed object lacks fields | parse to LocalDate or add time |
could not be parsed, unparsed text found at index 16 | trailing characters | use parse(CharSequence, ParsePosition) or trim |
| Formatter setup | Behaviour | When to use |
|---|---|---|
ofPattern("yyyy-MM-dd") | uses default locale | not recommended |
ofPattern("yyyy-MM-dd", Locale.ROOT) | locale independent | parsing machine data |
ISO_LOCAL_DATE | fixed ISO format | external APIs |
ofPattern(..., Locale.KOREA) | localised month names | human input |
parseBest | picks the first matching type | mixed offset input |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. Read the index, not the whole message
The index is measured in characters of the input, so it pinpoints the disagreement:
String[] inputs = {"2026-11-28 07:00", "2026-11-28T07:00", "28/11/2026 07:00"};
DateTimeFormatter f = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm");
for (String s : inputs) {
try {
System.out.println(LocalDateTime.parse(s, f));
} catch (DateTimeParseException e) {
System.out.println(s + " -> index " + e.getErrorIndex());
}
}
// 2026-11-28 07:00 -> ok
// 2026-11-28T07:00 -> index 10
// 28/11/2026 07:00 -> index 0An index of 0 means the first character is already wrong (day-first input against a year-first pattern); an index at a separator means the separator differs.
2. Accept several shapes with parseBest
Real input often mixes offset and local timestamps. parseBest returns the first type the text can satisfy, which turns a chain of try/catch blocks into one call:
DateTimeFormatter flexible = DateTimeFormatter.ofPattern(
"[uuuu-MM-dd['T'][ ]HH:mm[:ss][XXX]]", Locale.ROOT);
TemporalAccessor parsed = flexible.parseBest(
"2026-11-28 07:00",
ZonedDateTime::from, OffsetDateTime::from, LocalDateTime::from, LocalDate::from);
System.out.println(parsed.getClass().getSimpleName()); // LocalDateTimeSquare brackets mark optional sections, the supported way to model "with or without seconds and offset" without several formatters. The order of the method references matters: most specific type first.
3. Locale decides month names and week rules
Month names, week start and the meaning of Y depend on locale; parsing English month names with a Korean default fails at the month:
DateTimeFormatter en = DateTimeFormatter.ofPattern("d MMM uuuu", Locale.ENGLISH);
LocalDate d = LocalDate.parse("28 Nov 2026", en); // ok
DateTimeFormatter wrong = DateTimeFormatter.ofPattern("d MMM uuuu"); // default locale
LocalDate.parse("28 Nov 2026", wrong); // DateTimeParseExceptionUse Locale.ROOT or an explicit locale for machine data, and the JVM default only for text a human typed.
4. Strict versus smart resolution
DateTimeFormatter defaults to ResolverStyle.SMART, which resolves 2026-02-30 to 2026-02-28 in some paths and throws in others depending on the fields requested. Validation code should use STRICT and uuuu rather than yyyy:
DateTimeFormatter strict = DateTimeFormatter
.ofPattern("uuuu-MM-dd")
.withResolverStyle(ResolverStyle.STRICT);
LocalDate.parse("2026-02-30", strict);
// DateTimeParseException: Invalid date 'FEBRUARY 30'
LocalDate.parse("2026-11-28", strict); // okUsing yyyy with STRICT throws Unable to obtain LocalDate from TemporalAccessor, a confusing message for a pattern that looked correct.
5. Time zones and DST gaps
A LocalDateTime has no zone, so it cannot represent a DST transition; converting with atZone may throw or shift an hour depending on the resolver.
ZoneId seoul = ZoneId.of("Asia/Seoul");
ZonedDateTime z = LocalDateTime.parse("2026-11-28T07:00").atZone(seoul);
// gaps and overlaps
LocalDateTime gap = LocalDateTime.parse("2026-03-29T02:30"); // Europe: does not exist
gap.atZone(ZoneId.of("Europe/Berlin")); // shifted by default, throws with strict gap handlingWhen the source is an external system, parse an OffsetDateTime or Instant and convert to the display zone, rather than parsing a local time and guessing the zone later. For converting a parsed value to epoch seconds, the timestamp converter is quicker than a scratch Java file.
6. Parsing inside a loop
A DateTimeFormatter is immutable and thread-safe, so create it once as a static final field. Building it inside a hot loop costs time, and catching DateTimeParseException per row is expensive because the exception fills a stack trace:
private static final DateTimeFormatter CSV_TIME =
DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss", Locale.ROOT);
static Optional<LocalDateTime> parseRow(String value) {
try {
return Optional.of(LocalDateTime.parse(value, CSV_TIME));
} catch (DateTimeParseException e) {
return Optional.empty(); // caller counts bad rows
}
}Pre-validating with a regular expression avoids most exceptions; test the pattern with the regex tester before wiring it into the parser.
Common Compilation/Runtime Mistakes & Version Gotchas
yyyyinstead ofuuuu. WithSTRICTresolution, year-of-era without an era cannot be resolved;uuuuis the predictable choice.mmfor months orhhfor 24-hour time. Both produce parse failures far from the actual mistake in the pattern.- Catching
DateTimeParseExceptionasException. The specific type carriesgetErrorIndex(), the only cheap clue in the log. - Assuming
SimpleDateFormatbehaves the same. It is lenient by default, not thread-safe, and uses different pattern letters. - Version notes. Java 8 introduced
java.time;DateTimeFormatterhas been thread-safe since then, andResolverStyle.LENIENTstill resolves impossible dates instead of throwing, so validation logic must not rely on the default. Java 21 adds no changes to parsing behaviour. - Ignoring the offset in the input.
LocalDateTime.parseon a string with+09:00fails at the offset index; useOffsetDateTime.
Official documentation: DateTimeFormatter and DateTimeParseException.
Official references
primary documentationThe Java documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Java work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Java guides
All Java guidesSpring Boot: No qualifying bean of type available
The context could not satisfy a constructor argument. Scan boundaries, missing stereotypes, ambiguous candidates and test slices are the usual reasons.
Method Scope in Java: How Local Variables Work
Understand how variables behave inside Java methods: local variable boundaries, block scope, parameter scope, shadowing, and lifetime implications.
Java: HikariPool connection is not available, request timed out
The HikariCP pool ran out of connections for the whole connectionTimeout. Read the counters, find leaks or slow queries, then size the pool.
Java: java.net.BindException: Address already in use
The kernel refused the listening socket. Find the process holding the port, check the bound interface and privileged ports, then restart cleanly.
More in Java
All Java guidesThe guides filed next to this one in Java, in library order.