Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output an RFC-822 compatible date string with JavaScript?

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:

enter image description here

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?

like image 640
Šime Vidas Avatar asked Dec 15 '22 04:12

Šime Vidas


1 Answers

(new Date).toUTCString()

Documented at http://mdn.io/toUTCString

like image 167
Andy Pattenden Avatar answered Dec 28 '22 11:12

Andy Pattenden