Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse date in android

Tags:

java

android

I have the following code to pase a 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, 12 Aug 2011 15:34:47 CEST"

What is wrong ?

like image 979
Johan Avatar asked Dec 22 '22 10:12

Johan


2 Answers

You're missing the timezone in the date format at the end, in your exception message, the "CEST" part. Your code

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

should be

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

You might want to read SimpleDateFormat

Edit At the bottom of this page, the timezone format is more cleary explained Clearer Timezone format

like image 157
Jonathan Drapeau Avatar answered Jan 04 '23 21:01

Jonathan Drapeau


I think you need to add zzz in the end (for timezone):

"EEE, dd MMM yyyy kk:mm:ss zzz"
like image 25
MByD Avatar answered Jan 04 '23 20:01

MByD