Reputation: 41483
Does anyone have a function which can covert an RSS feeds pubDate to a unix timestamp? I tired using a javascript version of strtotime() but it never worked correctly.
Upvotes: 1
Views: 863
Reputation: 193
I think the simplest way to get the unix timestampt (this is time in seconds from 1/1/1970) it's as follows:
var myDate = new Date("Sun, 27 Mar 2011 20:17:21 +0100");
console.log(+myDate); // +myDateObject give you the unix from that date
console.log(+myDate + 60); // if you want to add seconds for example, you just sum the seconds that you want to add, since myDate is the time in seconds
Upvotes: 0
Reputation: 4320
var pubDate = "Sun, 27 Mar 2011 20:17:21 +0100";
var date = new Date(pubDate);
var timestamp = Math.round(date.getTime()/1000);
alert(timestamp);
Upvotes: 6
Reputation: 22941
Can be done easier using Date.parse:
var pubDate = "Sun, 27 Mar 2011 20:17:21 +0100";
alert(Math.round(Date.parse(pubDate)/1000));
Upvotes: 2