Frage

How to parse this string?

"Mon Jul 02 13:49:16 CEST 2012"

String Date = "Mon Jul 02 13:11:38 CEST 2012";
DateFormat formatter;
Date convertedDate= new Date();
formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
try {
     convertedDate = (Date) formatter.parse(Date);
} catch (ParseException ex) {
    Logger.getLogger(ItemRecTestCases.class.getName()).log(Level.SEVERE, null, ex);
        }

Dont work..."java.text.ParseException: Unparseable date:"

War es hilfreich?

Lösung

You need to set the locale :

formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.ENGLISH);

Or else "Mon" cannot be parsed as "monday".

Andere Tipps

The Locale needs to be specified:

formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top