Pregunta

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:"

¿Fue útil?

Solución

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".

Otros consejos

The Locale needs to be specified:

formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top