sebrock
sebrock

Reputation: 1244

SimpleDateFormat not working

I'm tearing my hair off my head on this one. Trying to parse this string into a Date object:

Fri, 28 Oct 2011 07:43:18 GMT

But it will not work. Instead I get an ParseException:

10-28 15:50:12.730: WARN/System.err(31232): java.text.ParseException: Unparseable date: Fri, 28 Oct 2011 07:43:18 GMT

The code I use is the following (and I have tried multiple tweaks to the formatting string to no avail):

SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:m:s zzz");

I know Javas Date and Time classes leaves a lot to wish for but this one is killing me...

Upvotes: 2

Views: 3826

Answers (2)

Naveen
Naveen

Reputation: 124

Use Locale.US. Try this instead

SimpleDateFormat dateFormat = new SimpleDateFormat("EEE dd MMM yyyy HH:m:s zzz", Locale.US);
Date date = dateformat.parse("Oct 28 09:53:19 2011"); 

Upvotes: 2

light_303
light_303

Reputation: 2111

your format looks more like this (double mm and double ss):

new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");

Upvotes: 6

Related Questions