最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - How to output an RFC-822 compatible date string with JavaScript? - Stack Overflow

programmeradmin0浏览0评论

I'm using Node.js to build my RSS file. I create a Date string with (new Date).toString() and then use that value for the <pubDate> field in the RSS file. However, when I run the Feed Validator, it reports that such a date string is not valid:

An example Date string that I generate is:

Fri Oct 25 2013 17:59:42 GMT+0200 (Central European Daylight Time)

If I understand correctly, in order to validate, there should be a comma after "Fri", and the "GMT" and the parens at the end should be removed. Is there an built-in way to produce such compliant strings with JavaScript or will I have to write a custom function to do this?

I'm using Node.js to build my RSS file. I create a Date string with (new Date).toString() and then use that value for the <pubDate> field in the RSS file. However, when I run the Feed Validator, it reports that such a date string is not valid:

An example Date string that I generate is:

Fri Oct 25 2013 17:59:42 GMT+0200 (Central European Daylight Time)

If I understand correctly, in order to validate, there should be a comma after "Fri", and the "GMT" and the parens at the end should be removed. Is there an built-in way to produce such compliant strings with JavaScript or will I have to write a custom function to do this?

Share Improve this question asked Oct 26, 2013 at 14:26 Šime VidasŠime Vidas 186k65 gold badges286 silver badges391 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 21

(new Date).toUTCString()

Documented at http://mdn.io/toUTCString

发布评论

评论列表(0)

  1. 暂无评论