在javascript中自定义日期以匹配格式

时间:2011-05-25 04:41:35

标签: javascript feeds

我正在尝试从我的RSS Feed中自定义日期,以显示它在Google Feed的主页http://code.google.com/apis/feed/“2011年5月12日”中的显示方式。我尝试修改谷歌操场上的代码(http://code.google.com/apis/ajax/playground/#historical_entries),但显示为2011年5月24日星期二13:02:48 GMT-0700(太平洋夏令时)为了我。我四处搜索,发现我必须使用google.feeds.ShortDatePattern,但无法弄清楚在哪里和如何。到目前为止,这是我的代码:

/*
*  How to see historical entries in a feed.  Usually a feed only returns x number
*  of results, and you want more.  Since the Google Feeds API caches feeds, you can
*  dig into the history of entries that it has cached.  This, paired with setNumEntries,
*  allows you to get more entries than normally possible.
*/

google.load("feeds", "1");

// Our callback function, for when a feed is loaded.
function feedLoaded(result) {
  if (!result.error) {
    // Grab the container we will put the results into
    var container = document.getElementById("content");
    container.innerHTML = '';

    // Loop through the feeds, putting the titles onto the page.
    // Check out the result object for a list of properties returned in each entry.
    // http://code.google.com/apis/ajaxfeeds/documentation/reference.html#JSON
    for (var i = 0; i < result.feed.entries.length; i++) {
      var entry = result.feed.entries[i];
      var date = new Date(entry.publishedDate);
      var div = document.createElement("div");
      var link = document.createElement("a");   
      link.setAttribute('href', entry.link);   
      link.appendChild( document.createTextNode( date + " " + entry.title));
      div.appendChild(link);
      container.appendChild(div);
      var content = document.createElement("div");
      content.appendChild(document.createTextNode(entry.contentSnippet));
      container.appendChild(content);
    }
  }
}

function OnLoad() {
  // Create a feed instance that will grab Digg's feed.
  var feed = new google.feeds.Feed("http://www.digg.com/rss/index.xml");

  feed.includeHistoricalEntries(); // tell the API we want to have old entries too
  feed.setNumEntries(5); // we want a maximum of 250 entries, if they exist

  // Calling load sends the request off.  It requires a callback function.
  feed.load(feedLoaded);
}

google.setOnLoadCallback(OnLoad);

1 个答案:

答案 0 :(得分:1)

你可以尝试像here

那样的简单的javascript