Redwall
Redwall

Reputation: 1020

new Date is formatting differently on Firefox and Chrome

I am passing this new Date into both Firefox and Chrome console (same computer, and time zone) and I am getting mixed results. Chrome is pushing the time forward to my time zone and Firefox is using the passed in time! So confusing...

Firefox

new Date("2014-02-27T17:00:00Z") // Passing in Console

// Result: Date 2014-02-27T17:00:00.000Z

Chrome / Safari

new Date("2014-02-27T17:00:00Z") // Passing in Console
// Result: Thu Feb 27 2014 18:00:00 GMT+0100 (CET)

It is 1 hour in the difference off. Chrome says the time is 18:00:00 while FF says the time is 17:00:00 which is what I expected seen as I formatted to Zulu (UTC) time.

Any help on how to get a consistent date on what is passed in to all browsers?

Thanks

Upvotes: 1

Views: 831

Answers (1)

Leo
Leo

Reputation: 13858

As you can see, Chrome gives you a local time (GMT+0100). That why the hour part is different.

You can try converting to UTC string.

new Date("2014-02-27T17:00:00Z").toUTCString()
// both Chrome and Firefox will give you "Thu, 27 Feb 2014 17:00:00 GMT"

Upvotes: 1

Related Questions