格式rss feed pubDate

时间:2012-08-03 13:36:17

标签: javascript

我正在尝试将rss Feed的日期格式化为月/日/年(2012年8月3日)。我正在使用以下代码执行此操作:

// 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.如何让它产生正确的月份?

演示:http://jsfiddle.net/LmZMX/

1 个答案:

答案 0 :(得分:3)

getMonth()返回"一个数字,从0到11,代表月份"

(postDate.getMonth() + 1)