How to convert a date in this format (Tue Jul 13 00:00:00 CEST 2010) to a Java Date (The string comes from an alfresco property)

Basically your problem is that you are using a SimpleDateFormat(String pattern) constructor, where javadoc says:

Constructs a SimpleDateFormat using
the given pattern and the default date
format symbols for the default locale.

And if you try using this code:

DateFormat osLocalizedDateFormat = new SimpleDateFormat("MMMM EEEE");
System.out.println(osLocalizedDateFormat.format(new Date()))

you will notice that it prints you month and day of the week titles based on your locale.

Solution to your problem is to override default Date locale using SimpleDateFormat(String pattern, Locale locale) constructor:

DateFormat dateFormat = new SimpleDateFormat(
            "EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
dateFormat.parse("Tue Jul 13 00:00:00 CEST 2011");
System.out.println(dateFormat.format(new Date()));

Leave a Comment