Format pubdate from RSS feed

pinaydiver's Avatar

pinaydiver

29 Mar, 2012 02:59 PM

I have this RSS pubDate -- Tue, 27 Mar 2012 01:00:00 -0400 . How do I convert to ''EEE, MM-dd-yy". Here is my original script:

#set ($items = $_XPathTool.selectNodes($contentRoot, "/rss/channel/item"))
#foreach ($item in $items)
    # set ( $pubDate = $_DateTool.toDate("EEE, MM-dd-yyyy",$item.getChild("pubDate").value ) ) 
    $pubDate
#end
  1. Support Staff 2 Posted by Charlie Holder on 29 Mar, 2012 03:06 PM

    Charlie Holder's Avatar

    Looks like you might just want to adjust the mask that's being used on the .toDate() method. What happens when you change that to be the format you listed?

  2. 3 Posted by pinaydiver on 29 Mar, 2012 03:14 PM

    pinaydiver's Avatar

    it does not return a value.

  3. Support Staff 4 Posted by Charlie Holder on 29 Mar, 2012 03:24 PM

    Charlie Holder's Avatar

    What does this do?

    #set ($items = $_XPathTool.selectNodes($contentRoot, "/rss/channel/item"))
    #foreach ($item in $items)
        #set ( $pubDate = $_DateTool.toDate("EEE, MM-dd-yyyy",$item.getChild("pubDate").value ) )
        #set ( $newPubDate = $_DateTool.format("EEE, MM-dd-yy", $pubDate )
        $newPubDate
    #end
    
  4. 5 Posted by pinaydiver on 29 Mar, 2012 03:29 PM

    pinaydiver's Avatar

    It gives returns this value=> $newPubDate

  5. Support Staff 6 Posted by Charlie Holder on 29 Mar, 2012 03:51 PM

    Charlie Holder's Avatar

    I think there's an error with my code up there. Did you catch that when you tested? I'm missing a closing paren.

    Syntax corrected:

    #set ($items = $_XPathTool.selectNodes($contentRoot, "/rss/channel/item"))
    #foreach ($item in $items)
        #set ( $pubDate = $_DateTool.toDate("EEE, MM-dd-yyyy",$item.getChild("pubDate").value ) )
        #set ( $newPubDate = $_DateTool.format("EEE, MM-dd-yy", $pubDate) )
        $newPubDate
    #end
    
  6. 7 Posted by pinaydiver on 29 Mar, 2012 05:20 PM

    pinaydiver's Avatar

    This returns --> $newPubDate .

  7. Support Staff 8 Posted by Charlie Holder on 29 Mar, 2012 05:40 PM

    Charlie Holder's Avatar

    It's probably a matter of matching the output from the RSS feed then. The .toDate mask that you're passing should match what's being returned from the pubDate node in the RSS feed.

    Create a new mask that matches "Tue, 27 Mar 2012 01:00:00 -0400" using these patterns and see if that helps.

  8. 9 Posted by pinaydiver on 29 Mar, 2012 05:56 PM

    pinaydiver's Avatar

    Thanks Charlie. It is now working. I revised the script as follows:

    #set ( $pubDate = $_DateTool.toDate("EEE, d MMM yyyy HH:mm:ss Z",$item.getChild("pubDate").value ) )
        #set ( $newPubDate = $_DateTool.format("EEE, MMM d, yyyy", $pubDate) )
        $newPubDate
    
  9. Bradley Wagner closed this discussion on 29 Mar, 2012 10:06 PM.

Comments are currently closed for this discussion. You can start a new one.