Nayan Wadekar
Nayan Wadekar

Reputation: 11622

String to Date Parsing not working

I am getting date as string as a parameter from Servlet. Now when I am trying to parse it again to get util.Date, it gives me error.

I am getting string "Fri Jul 02 00:00:00 IST 2010" & I want util.Date from it. Tried SimpleDateFormat, DateFormat but didn't work.

Upvotes: 0

Views: 585

Answers (2)

Bozho
Bozho

Reputation: 597382

The exact date format of your string-represented date is:

DateFormat df = new SimpleDateFormat("E MMM dd HH:mm:ss z yyyy");

But I would suggest on configuring your custom format, and use it for converting back and forth.

Upvotes: 3

Pat
Pat

Reputation: 25685

As long as you set the format of your date string, it should work:

Parsing a date using a custom format

My guess is that you don't have the SimpleDateFormat string set properly. Try starting with a simple date String (dd/MM/yyyy) and seeing if you can get that to work.

Upvotes: 0

Related Questions