javaparsingdate

How to parse this date in Java


Please tell me how to parse this string: "29-July-2012".

I tried:

new SimpleDateFormat("dd-MMM-yyyy");

… but it doesn’t work. I get the following exception:

java.text.ParseException: Unparseable date: "29-July-2012"


Solution

  • You need to mention the Locale as well...

    Date date = new SimpleDateFormat("dd-MMMM-yyyy", Locale.ENGLISH).parse(string);