JavaScript Date Object Chrome vs. Firefox

There is a very tiny yet important difference between how Chrome and Firefox treats “Date” object, when you are creating one from a String:

new Date("1980-03-14T00:00:00.0000000");

The difference is that Firefox (tested on v23.0.1) considers the passed string is on the local timezone so the output is:

new Date("1980-03-14T00:00:00.0000000").toString();
"Fri Mar 14 1980 00:00:00 GMT-0400 (Eastern Standard Time)"

While Chrome, considers the passed string in UTC/GMT timezone and then converts it to a local timezone:

new Date("1980-03-14T00:00:00.0000000").toString();
"Thu Mar 13 1980 20:00:00 GMT-0400 (Eastern Daylight Time)"

As you can see, that would be a potential for some Front-End Date/Time processing.

If you are using the Date object just for showing, using the UTC format would be very useful and would avoid any discrepancies.

var my_time =  new Date("1980-03-14T00:00:00.0000000");

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s