Parsing date in android

I have the following code to set the date

DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss", Locale.getDefault()); Date _pubDate = df.parse(_pubDateE.getFirstChild().getNodeValue()); 

But I get this error:

java.text.ParseException: Unparseable date: "Fri, Aug 12, 2011 3:34:47 PM CEST"

What's wrong?

+4
source share
4 answers

You are missing the time zone in the date format at the end, in your exception message, in the "CEST" part. Your code

 DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss", Locale.getDefault()); 

it should be

 DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss z", Locale.getDefault()); 

You might want to read SimpleDateFormat

Change At the bottom of this page, the time zone format is clearer. A clearer time zone format

+7
source

I think you need to add zzz at the end (for the time zone):

 "EEE, dd MMM yyyy kk:mm:ss zzz" 
+4
source

The date string is not specified in the specified format. Pay attention to the time zone at the end?

0
source

You probably want: new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss zzz", Locale.getDefault());

0
source

All Articles