I get this date in javascript from an rss-feed (atom):
2009-09-02T07:35:00+00:00
If I try Date.parse on it, I get NaN.
How can I parse this into a date, so that I can do date-stuff to it?
I get this date in javascript from an rss-feed (atom):
2009-09-02T07:35:00+00:00
If I try Date.parse on it, I get NaN.
How can I parse this into a date, so that I can do date-stuff to it?
You can convert that date into a format that javascript likes easily enough. Just remove the 'T' and everything after the '+':
var val = '2009-09-02T07:35:00+00:00',
date = new Date(val.replace('T', ' ').split('+')[0]);
Update: If you need to compensate for the timezone offset then you can do this:
var val = '2009-09-02T07:35:00-06:00',
matchOffset = /([+-])(\d\d):(\d\d)$/,
offset = matchOffset.exec(val),
date = new Date(val.replace('T', ' ').replace(matchOffset, ''));
offset = (offset[1] == '+' ? -1 : 1) * (offset[2] * 60 + Number(offset[3]));
date.setMinutes(date.getMinutes() + offset - date.getTimezoneOffset());
Robert L's implementation works well. I'd vote it up but I don't have enough rep points.