Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My date drives me crazy (Java)

I need to convert a string to a Date object using SimpleDateFormat.

I use "MMM. dd yyyy" to parse strings like "Dec. 30 2011", with 3 month char and a dot.

It fails for "May 30 2011" so I have to catch the exception and re-try with "MMM dd yyyy". It works for "May", so far so ugly but works.

But when it get to "Sept. 11 2011", all of the above plus "MMMM. dd yyyy" and "MMMM dd yyyy" fail. So I can't parse it at all.

What is going on?

like image 924
user2720403 Avatar asked Dec 05 '25 20:12

user2720403


1 Answers

try this pattern -

MMM'.' dd yyyy

Code -

DateFormat df = new SimpleDateFormat("MMM'.' dd yyyy");
Date date = df.parse("Dec. 30 2011");

Hope it will help you to make fun :)

like image 154
Subhrajyoti Majumder Avatar answered Dec 08 '25 08:12

Subhrajyoti Majumder



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!