0

I want to parse a String into a Date, but my SimpleDateFormat doesn't work. Everytime I get a ParseException. Whats wrong with my SimpleDateFormat? The datestring I want to parse looks like this:

Mon Dec 17 00:00:00 CET 2012

public Date toLongDate(String date) {
    try {
        return date != null ? new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy").parse(date) : null;
    } catch (ParseException e) {
        throw new RuntimeException("cannot parse date " + date);
    }
}

best regards

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
BHuelse
  • 2,889
  • 3
  • 30
  • 41
  • 1
    look at this : http://stackoverflow.com/questions/19861642/date-format-parse-exception-eee-mmm-dd-hhmmss-z-yyyy – Zakaria Mar 16 '16 at 16:49
  • The code does not throw any exception unless the locale used is collided. – Tiny Mar 16 '16 at 16:56

1 Answers1

2

Try doing with locale as argument:

final String sss = "Mon Dec 17 00:00:00 CET 2012";
final Date d = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.US).parse(sss);
System.out.println(d);

Output:

Mon Dec 17 00:00:00 CET 2012

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97