Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse RSS pubDate to Date object in JavaScript

How would I do this?

Tue, 2 Feb 2010 19:34:21 Etc/GMT

like image 278
Vitaly Avatar asked Feb 03 '10 10:02

Vitaly


1 Answers

It works right out of the box. The Date object in JavaScript can be set by passing a number of standard time formats. The format used in RSS is one of these.

Example:

var pubDate = "Sun, 27 Mar 2011 20:17:21 +0100";
var date = new Date(pubDate);

var months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var string = date.getDate() + " " + months[date.getMonth()] + " " + date.getFullYear()

alert(string);
like image 109
Oliver Moran Avatar answered Oct 05 '22 23:10

Oliver Moran