DateTimeParseException ☕ Java

java.time.format.DateTimeParseException: Text '31/12/2024' could not be parsed at index 2

A java.time parse call got text that doesn’t match the expected format.

Seen on: Java

Meaning

LocalDate.parse() expects ISO format (2024-12-31) unless you pass a DateTimeFormatter. The index points to the first mismatching character.

Common causes

  • Non-ISO input without a formatter
  • Wrong pattern letters (MM vs mm, yyyy vs uuuu)
  • Locale-specific month names
  • Time zone suffix not in pattern

⚡ Quick fix

  1. Use a formatter: DateTimeFormatter.ofPattern("dd/MM/yyyy")
  2. Prefer ISO strings in APIs
  3. Use OffsetDateTime for zone offsets

Detailed fix by platform

Java

  1. LocalDate d = LocalDate.parse("31/12/2024", DateTimeFormatter.ofPattern("dd/MM/yyyy"));

How to diagnose

  1. Text — Which string and index?
  2. Pattern — Matches the input?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.