解析RSS发布日期

时间:2013-02-27 17:51:30

标签: javascript html

我正在尝试从RSS源解析已发布的日期,但没有成功......

我可以使用以下代码显示日期:thefeeds[i].publishedDate ..结果是:Sat, 02 Feb 2013 22:00:00 -0800但是,我希望这更友好...

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>

    <script type="text/javascript">

        var feedcontainer=document.getElementById("feeddiv")
        var feedurl="http://feeds.folha.uol.com.br/folha/classificados/empregos/rss091.xml"
        var feedlimit=4
        var rssoutput="<ul>"
        function rssfeedsetup(){
            var feedpointer=new google.feeds.Feed(feedurl) //Google Feed API method
            feedpointer.setNumEntries(feedlimit) //Google Feed API method
            feedpointer.load(displayfeed) //Google Feed API method
        }

        function displayfeed(result){
            if (!result.error){
                var thefeeds=result.feed.entries
                for (var i=0; i<thefeeds.length; i++){

<!-- I THINK I'M DOING THIS LINES WRONG!! -->
                var pubDate = thefeeds[i].publishedDate
                var date = new Date(pubDate);
                var months = Array("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro");
                var string = date.getDate() + " " + months[date.getMonth()] + " " + date.getFullYear()

<!-- END -->

                rssoutput+="<li><span>•</span> " + string + " - <a href='" + thefeeds[i].link + "' target='_blank'>" + thefeeds[i].title + "</a></li>"
                rssoutput+="</ul>"
                feedcontainer.innerHTML=rssoutput
            }
            else
            alert("Erro ao carregar as notícias!")
        }

        window.onload=function(){
            rssfeedsetup()
        }
        </script>

怎么了?

1 个答案:

答案 0 :(得分:0)

似乎缺少了一个parentesis(在for-Loop中),但我不确定它是否只是一个复制粘贴错误。 像这样,代码将循环设置 i 到不在数组中的数字......

 ...
 for (var i=0; i<thefeeds.length; i++)
 //--> here  is missing {
 ...
 //--> at the end of the block }
 ...