Search code examples
xml-parsingrssfeed

Find out what time zone an RSS feed item was published


I'm parsing an RSS 2.0 feed which has missing time zone information in its pubDate tag.

For example, the element is written as such:

<pubDate>Tue, 3 Dec 2013 09:00:00</pubDate>

How can I figure out or find out the time zone from this node element?


Solution

  • If you cannot infer or tell what the time zone is for an RSS feed item, then the item is not valid.

    A valid <pubDate> element will include the time zone, or time zone hours offset.

    According to the RSS 2.0 specifications,

    All date-times in RSS conform to the Date and Time Specification of RFC 822, with the exception that the year may be expressed with two characters or four characters (four preferred).

    The following are valid examples, and you can determine what time zone the item was published at:

    <pubDate>Wed, 02 Oct 2002 08:00:00 EST</pubDate>
    
    <pubDate>Wed, 02 Oct 2002 13:00:00 GMT</pubDate>
    
    <pubDate>Wed, 02 Oct 2002 15:00:00 +0200</pubDate>
    

    The options available then are to ask the feed publisher to update the <pubDate> field with the correct date format, or somehow note what time zone you believe the particular source is publishing from.