Date.parse problem!

I have a program that parses the same date differently using the same function.

The date is a string from facebook:


In one part of my js program, I execute:
created_at = Date.parse(“2010-07-19T18:00:52+0000”)

On another page, I execute the same:
created_at = Date.parse(“2010-07-19T18:00:52+0000”)

Displaying created_at in my html will yield either

Mon, 19 Jul 2010 19:48:59 GMT or
Mon Jul 19 2010 19:48:59 GMT-0700 (PST)

Ideally I’d like the date to be read as a GMT. Are there global settings to Date that I should be setting to get consistent interpretation of the fb string?


It turns out to be my error. Date.parse() is actually not parsing the same value on the different pages. One page is parsing the facebook value, the other (working one) is parsing an already parsed date.

Incidently, it turns out that Date.parse is coming from the jquery.daterangepicker module…

Thanks for the reply,

I’m surprised that works. This line:

created_at =  Date.parse("2010-07-19T18:00:52+0000")

doesn’t work. Date.parse can’t handle strings like that. In any case, once you have somehow parsed your date, you can use toUTCString() to convert things to GMT. But you will need to turn that string returned into a Date object first. Example:

var sometime = new Date(Date.parse('Wed 07 Jul 2010 13:24:30 GMT-0530'));