javascript - 格式化 RSS feed pubDate

标签 javascript

我正在尝试将 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。我如何让它产生正确的月份?

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

最佳答案

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

(postDate.getMonth() + 1)

关于javascript - 格式化 RSS feed pubDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11796843/

相关文章:

javascript - 需要加密在数据库中存储值

c# - 没有回发的事件

javascript - AngularJS 语法错误 : Unexpected token {

javascript - 超链接到 GitHub 项目 HTML 作为带有参数的预览

javascript - 使用 JSON 数据创建 HTML 表时遇到问题

javascript - 从base64得到的数组的值是多少

javascript - 我无法正确输出

javascript - 如何使用cropper.js对图像进行裁剪?

javascript - 将变量从一个函数传递到另一个函数

javascript - 从具有相同类的字段中获取值,添加到数组