0

I'm reading from a RSS feed which outputs date/time in the following format:

Day, DD Mon YYYY HH:MM:SS OFFSET

For example,

Tue, 24 Apr 2012 08:15:00 -0700

Using JavaScript,I need to convert it to an ISO8601 string (via Date.toISOString() preferably).

Any assistance would be appreciated.

I haven't really worked with time in JS before, so I haven't got many ideas. Would it be possible to switch the offset to a time zone, and convert it as a JS Date object?

Community
  • 1
  • 1
azz
  • 5,852
  • 3
  • 30
  • 58
  • The only thing I can think of is converting the offset to actual time zones, then converting it with `Date.toISOString()`. – azz Apr 24 '12 at 16:24

1 Answers1

1

u can do that with the date object (at least it is working for me in chrome)

var test = new Date("Tue, 24 Apr 2012 08:15:00 -0700");
test.toISOString() // "2012-04-24T15:15:00.000Z"

I hope it is the correct output... not sure

Tobias Krogh
  • 3,768
  • 20
  • 14
  • Oh now I just feel dumb for not having tried that... Thanks for this. – azz Apr 24 '12 at 16:46
  • I do not know how older browsers are dealing with it... but I think this should work cross-browser – Tobias Krogh Apr 24 '12 at 16:48
  • I'm actually developing a Windows Sidebar gadget, which runs on HTML/JS/CSS. It's working well, I was over-thinking again... – azz Apr 24 '12 at 16:56
  • Usually there's no reason to drop the timezone information. See http://stackoverflow.com/a/15302113/277267 – Daniel F Mar 08 '13 at 19:58