Q:

Convert String to Date with usage of SimpleDateFormat

I want to convert a String to a Date but I get the following exception:
java.text.ParseException: Unparseable date: "Thu Jan 27 14:47:58 CET 2011"
    at java.text.DateFormat.parse(DateFormat.java:335)
    at de.datev.boxi.Main.run(Main.java:36)
    at com.crystaldecisions.sdk.plugin.desktop.program.internal.ProgramWrapper.main(ProgramWrapper.java:174)

Which parameters should I use to format the String to a Date?
My program looks like:
try {
    SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
    Date d1 = sdf.parse("Thu Jan 27 14:47:58 CET 2011");
    System.out.println(d1);
} catch (ParseException ex) {
    ex.printStackTrace();
}

A:

Try with:
new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);

A:

Parsing such "complicated" time stamps is always tricky in Java. I had the same experience.
Either Java has a problem parsing your Time-Zone.
Or even more likely the default locale doesn't match your time string, where I would suggest to add the English locale to your call:
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);

I would always suggest to add this parameter, as depending on the execution environment your applications could work on some and fail on other machines - depending on the default locale.

