The sample code speaks for itself:
private void parse() throws ParseException{
SimpleDateFormat sdf = new SimpleDateFormat("MMM/dd/yyyy");
Date started = sdf.parse("Sep/22/2004");
// this triggers: java.text.ParseException: Unparseable date: "May/23/2010"
Date ended = sdf.parse("May/23/2010");
}
Not sure what more I can add to this. I'm trying to parse "MMM/dd/yyyy" dates, and I get inconsistent exception behavior. It feels like I'm missing something obvious.
It was of course locale related. Add the following:
sdf.setDateFormatSymbols(DateFormatSymbols.getInstance(Locale.ENGLISH));
Or alternatively simply declare it with locale:
SimpleDateFormat sdf = new SimpleDateFormat("MMM/dd/yyyy", Locale.ENGLISH);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With