Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse RSS pubDate to Date object in java

How can I parse a pubDate from a RSS feed to a Date object in java.

The format in the RSS feed: Sat, 24 Apr 2010 14:01:00 GMT

What I have at the moment:

DateFormat dateFormat = DateFormat.getInstance(); Date pubDate = dateFormat.parse(item.getPubDate().getText()); 

But this code throws an ParseException with the message Unparseable date

like image 951
Derk Avatar asked Apr 24 '10 18:04

Derk


1 Answers

You can define the date format you are trying to parse, using the class SimpleDateFormat:

DateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz"); Date date = formatter.parse("Sat, 24 Apr 2010 14:01:00 GMT"); 

Additionally, for non-English Locale's, be sure to use the following when parsing dates in English:

new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH); 
like image 52
João Silva Avatar answered Oct 11 '22 20:10

João Silva