views:

76

answers:

2

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.

A: 

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.

Pat
+3  A: 

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.

Bozho
I think that should be `HH:mm:ss` instead of `hh:mm:ss`: `HH` is hours in the format 0-23, `hh` is 1-12. There's no AM/PM indication in the string.
Jesper
@Jesper thanks, updated
Bozho