我使用Google Feed API创建了RSS Feed,我需要从发布日期中删除“已发布时间”并仅显示“日期”。
我有这段代码。
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++)
rssoutput += "<li><a href='" + thefeeds[i].link + "'>" + thefeeds[i].publishedDate + "</a></li>"
rssoutput += "</ul>"
feedcontainer.innerHTML = rssoutput
}
else
alert("Error fetching feeds!")
}
window.onload = function () {
rssfeedsetup()
}
任何人都可以帮忙吗?
答案 0 :(得分:0)
您可以使用 publishedDate字符串在javascript中创建日期,并提取年,月和天。
var dt = new Date(thefeeds[i].publishedDate);
dt.getFullYear() + '/' + (dt.getMonth() + 1) + '/' + dt.getDate();
getMonth()你需要+1 cuz getMonth返回数组,所以它从0开始