Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing of string to Date Object

Tags:

java

I have string "Tue Nov 12 2010",I want to parse it in java.util.Date object. I write below code for this

DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
Date date= format.parse("Tue Nov 12 2010");

It is giving exception like below:

java.text.ParseException: Unparseable date: "Sun Nov 21 2010"

Not getting what is wrong with it???

like image 885
Sanjay Jain Avatar asked Nov 23 '25 09:11

Sanjay Jain


1 Answers

Your format is wrong - if you specify a format dd/MM/yyyy, then you need to supply the string to be formatted in the corresponding format (!) e.g. 21/11/2010.

like image 178
Armand Avatar answered Nov 24 '25 23:11

Armand



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!