0

I get an error:

Unparseable date: "Thu Aug 01 00:00:00 EEST 2019"

I tried following other examples on stackoverflow but it didn't work, so my question is not duplicate, I genuinely can't get it working. I don't understand why because my code looks like this:

try {
  // "Thu Aug 01 00:00:00 EEST 2019"
  String dateString = pageParameters.get("dtFrom").toString();
  Date date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(dateString);
  System.out.println(date);
} catch (ParseException e) {
  e.printStackTrace();
}
developer1
  • 527
  • 4
  • 27
  • For me your code is working. – tobsob Aug 28 '19 at 12:11
  • 1
    What version of Java are you using? What language does your computer have? I tried the code and it works fine for me. – eric.m Aug 28 '19 at 12:13
  • Unable to replicate the problem. – Yash Aug 28 '19 at 12:23
  • IntelliJ IDEA 2018.3.4 (Community Edition) Build #IC-183.5429.30, built on January 29, 2019 JRE: 1.8.0_152-release-1343-b26 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 10 10.0 – developer1 Aug 28 '19 at 12:33
  • When I evaluate: `Date date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(dateString);` I get `Method threw 'java.text.ParseException' exception.` – developer1 Aug 28 '19 at 12:34
  • 1
    I recommend you don’t use `SimpleDateFormat` and `Date`. Those classes are poorly designed and long outdated, the former in particular notoriously troublesome. Instead use `ZonedDateTime` and `DateTimeFormatter`, both from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). – Ole V.V. Aug 28 '19 at 12:36

1 Answers1

1

I think I resolved your problem. For me this doesn't work either.

Your date's day and month are in English (Thuesday and august). My problem was that my default locale is in Spanish, so the day and the month name must be in spanish.

You can see your locale default with:

System.out.println(Locale.getDefault());

If your locale is not english you must change it, and it should work.

Hope this helps.

Diego
  • 89
  • 5