2

I'm trying to convert a string to a date. I've got an example here with the input string as hardcoded string.

try {
    String currentDate = "Tue Jan 05 21:19:57 CET 2016";
    Date d = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US).parse(currentDate);
} catch (ParseException e) {
    e.printStackTrace();
}

For some reason, this throws the following exception:

ParseException: Unparseable date: "Tue Jan 05 21:19:57 CET 2016" (at offset 20)

Could someone help me with this problem? Thanks!

Corne Elshof
  • 199
  • 3
  • 9
  • *"this throws the following exception"* ... well, not for me. Have copy pasted this code snippet? – Tom Jan 05 '16 at 22:13
  • 1
    please change the current local and try to run this code again to make sure that issue related to local, tired with different local but not US and I have the same exception – Ahmad Al-Kurdi Jan 05 '16 at 22:33
  • 1
    Small addition to @AhmadAl-Kurdi's comment, CET is Central European Time – simonl Jan 05 '16 at 22:37

1 Answers1

1

Your problem is described her java.text.ParseException: Unparseable date

Your machine Local can effect the local that used in SimpleDateFormat

Community
  • 1
  • 1
Ahmad Al-Kurdi
  • 2,248
  • 3
  • 23
  • 39