Last active
September 24, 2019 11:58
-
-
Save samhernandez/5260558 to your computer and use it in GitHub Desktop.
Get an RSS pubDate from a Javascript Date instance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get an RSS pubDate from a Javascript Date instance. | |
* @param Date - optional | |
* @return String | |
*/ | |
function pubDate(date) { | |
if (typeof date === 'undefined') { | |
date = new Date(); | |
} | |
var pieces = date.toString().split(' '), | |
offsetTime = pieces[5].match(/[-+]\d{4}/), | |
offset = (offsetTime) ? offsetTime : pieces[5], | |
parts = [ | |
pieces[0] + ',', | |
pieces[2], | |
pieces[1], | |
pieces[3], | |
pieces[4], | |
offset | |
]; | |
return parts.join(' '); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot!