Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse this date in Java

Tags:

java

date

parsing

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"

like image 933
rocknow Avatar asked Oct 27 '25 05:10

rocknow


1 Answers

You need to mention the Locale as well...

Date date = new SimpleDateFormat("dd-MMMM-yyyy", Locale.ENGLISH).parse(string);
like image 189
Bharat Sinha Avatar answered Oct 28 '25 19:10

Bharat Sinha



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!