我正在尝试将 RSS feed 的日期格式设置为月/日/年 (8/3/2012)。我使用以下代码来做到这一点:
// pubDate
postDate = new Date("Fri Aug 03 2012 06:08:11 GMT-0700");
// reformat pubDate
pubDate = postDate.getMonth() + "/" + postDate.getDate() + "/" + postDate.getFullYear();
// return pubDate
console.log(pubDate + " pubDate");
使用我当前的代码,输出为 7/3/2012,但月份不正确。我得到 7 而不是 8。我如何让它产生正确的月份?
最佳答案
getMonth()返回“一个数字,从 0 到 11,代表月份”
(postDate.getMonth() + 1)
关于javascript - 格式化 RSS feed pubDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11796843/