Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java date parsing issue

Tags:

java

datetime

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?

like image 251
aveschini Avatar asked May 05 '26 05:05

aveschini


1 Answers

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"));
like image 143
Arnaud Denoyelle Avatar answered May 06 '26 18:05

Arnaud Denoyelle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!