Date format parse exception - "EEE MMM dd HH:mm:ss Z yyyy"

PDS picture PDS · Nov 8, 2013 · Viewed 64.8k times · Source

I got problem with date parse example date:

SimpleDateFormat parserSDF=new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy", Locale.getDefault());


parserSDF.parse("Wed Oct 16 00:00:00 CEST 2013");

got exception

Exacly I want parse this format date to yyyy-MM-dd I try:

SimpleDateFormat parserSDF = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
Date date = parserSDF.parse("Wed Oct 16 00:00:00 CEST 2013");

take : java.text.ParseException: Unparseable date: "Wed Oct 16 00:00:00 CEST 2013"


OK I change to and works :

SimpleDateFormat parserSDF = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy", Locale.ENGLISH);
Date date = parserSDF.parse("Wed Oct 16 00:00:00 CEST 2013");

Answer

Sotirios Delimanolis picture Sotirios Delimanolis · Nov 8, 2013

I'm going to assume that Locale.getDefault() for you is pl-PL since you seem to be in Poland.

English words in date strings therefore cause an unparseable date.

An appropriate Polish date String would be something like

"Wt paź 16 00:00:00 -0500 2013"

Otherwise, change your Locale to Locale.ENGLISH so that the SimpleDateFormat object can parse String dates with English words.