2012-08-03 103 views
2

我想格式rss饲料的日期为月/日/年(8/3/2012)。我正在用下面的代码:格式rss feed pubDate

// 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/

回答

3

getMonth()回报 “一个数字,从0到11,代表月”

(postDate.getMonth() + 1) 
+0

笑,解释它。谢谢! – 2012-08-03 13:41:53