Yuriy Kolbasinskiy
Yuriy Kolbasinskiy

Reputation: 3841

ParseException when parse date via SimpleDateFormat

I'm trying to parse date from string to Date My string date is: Fri Apr 30 01:20:29 +0700 2010

My code is:

SimpleDateFormat format = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy");            
Date date = format.parse(input);

But i'm getting an Unparsable date exception. What's wrong?

Upvotes: 1

Views: 74

Answers (1)

Gaël J
Gaël J

Reputation: 15050

Check your format, you only have one E instead of three :

EEE MMM dd HH:mm:ss Z yyyy

EDIT : also check your JVM's language locale or specify one for your call.

As writen in comments, following code works :

SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.US);

Upvotes: 3

Related Questions