99miles
99miles

Reputation: 11212

Format javascript date to match rails format

I get a date back from rails that looks like: "2010-10-29T00:00:00+00:00"

And I'd like to convert a javascript date created by 'new Date()' to that format. Is there an easy way?

Upvotes: 3

Views: 3055

Answers (3)

rvandervort
rvandervort

Reputation: 341

You're looking for ISO 8601 format.

I've always been fond of the Date.js Library for any date manipulation/formatting in JS.

you can use the the toISOString() method to get this format

Upvotes: 4

clarkf
clarkf

Reputation: 3052

Looks like you're trying to parse an ISO8601 date string. A quick google search returned a function at dansnetwork.com that claims to be able to parse ISO8601 strings into Date objects. Or you could try parsing it yourself (Check out String.split(), and the Date api.). Luckily for you, I believe I read somewhere that Mozilla's Javascript 1.8.5 is going to support ISO8601 strings in its native parse() function. Hopefully the rest will follow suit shortly.

Upvotes: 0

Related Questions