1
String date = "5th Apr 1920";   
LocalDate.parse(date, DateTimeFormatter.ofPattern("d MMM yyyy", Locale.ENGLISH));

this prases DateTimeParseException.

If pattern is "d'th' MMM yyyy", it works. But it is unsuitable when string is "1st Apr 1920".

payboy
  • 11
  • 1

1 Answers1

1

Just specify more options:

LocalDate.parse(date, DateTimeFormatter
  .ofPattern("d['th']['st']['nd']['rd'] MMM yyyy", Locale.ENGLISH))
Eugene
  • 110,516
  • 12
  • 173
  • 277