aveschini
aveschini

Reputation: 1712

Java date parsing issue

I have an exception in parsing a date from a string:

java.text.ParseException: Unparseable date: "16 May 2013 19:27:12" (at offset 3)

but i think that i'm using the right pattern:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy HH:mm:ss");

try {
    done = true;
    date = simpleDateFormat.parse(dateString);
} catch (ParseException e) {
    e.printStackTrace();
    done = false;
}
if (done) {
    return date;
}

Somebody can help? What am I doing wrong?

Upvotes: 3

Views: 252

Answers (1)

Arnaud Denoyelle
Arnaud Denoyelle

Reputation: 31215

The problem is the interpretation of "May" because you did not specify any locale.

Try :

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy HH:mm:ss", new Locale("en_US"));

Upvotes: 12

Related Questions