0

I have a Java application which basically contains the following code in a test and expects it to throw an Exception:

String date = "Fr August 21 16:41:32 CEST 2015";
DateFormat dateFormat = new SimpleDateFormat("EEE MMMM dd HH:mm:ss z yyyy", Locale.GERMANY);
dateFormat.parse(date);

While the application ran under Suns Java 1.7 it always failed, as expected, with this Exception:

java.text.ParseException: Unparseable date: "Fr August 21 16:41:32 CEST 2015"

It failed because CEST wasn't a legit time zone with German Locale. When I now run the same test under IBMs Java 1.8, it now successfully parses to

Fr August 21 16:41:32 MESZ 2015

So I wonder which behaviour is the correct one? Do I now have a bug or did I have one before? Or did I somehow miss-configure something?

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Jdv
  • 962
  • 10
  • 34
  • Interesting question with no clear-cut answer, I’m afraid. Java gets its locale data — what the day abreviations and time zone names are in different languages — from up to four sources, and not the same sources in all Java versions. It’s a long time since I’ve worked with IBM Java, but I would think the behaviour is as IBM intended. – Ole V.V. Sep 26 '18 at 14:40
  • FWIW on my Java 10.0.2 too I get `java.text.ParseException: Unparseable date: "Fr August 21 16:41:32 CEST 2015"`. – Ole V.V. Sep 26 '18 at 14:42
  • I recommend you avoid the `SimpleDateFormat` class. It is not only long outdated, it is also notoriously troublesome. Today we have so much better in [`java.time`, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). Will be curious whether it solves your problem, though, since it still uses Java’s changing locale data. – Ole V.V. Sep 26 '18 at 14:44
  • Is your default locale `Locale.GERMANY` too? – Ole V.V. Sep 26 '18 at 14:47

0 Answers0