开发者

Customize date in javascript to match a format

I am trying to customize date from my RSS feed to display like how its displayed on the google feed's mainpage http://code.google.com/apis/feed/ "May 12, 2011". I tried modifying the code on the google playground (http://code.google.com/apis/ajax/playground/#historical_entries)but its displaying as Tue May 24 2011 13:02:48 GMT-0700 (Pacific Daylight Time) for me. I searched around and found that I have to use google.feeds.ShortDatePattern but cannot figure out where and how. This is my code so far :

/*
*  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 callba开发者_JS百科ck function.
  feed.load(feedLoaded);
}

google.setOnLoadCallback(OnLoad);


you can try plain ol' javascript like here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜