Reputation: 21
Why is the following code throws ParseException?
DateFormat df = new SimpleDateFormat("MMM d, yyyy");
String date = "Jan 1, 2011";
df.parse(date);
Result:
java.text.ParseException: Unparseable date: "Jan 1, 2011"
Upvotes: 2
Views: 1490
Reputation: 25950
It's related with the Locale parameter as @Gijs Overvliet mentioned. For instance, I'm using Turkish locale and my String should be set accordingly.
public static void main(String[] args) throws ParseException
{
DateFormat df = new SimpleDateFormat("MMM d, yyyy", Locale.getDefault());
String date = "Oca 1, 2011";
df.parse(date);
}
Upvotes: 2