Search code examples
javascriptdatefirefoxiceweasel

Javascript new Date() changed in firefox?


So I was wondering if the javascript function Date() recently changed for Firefox or even other browsers.

At first I would get a date output like this: Mon Apr 13 2015 22:18:08 GMT+0200 (West-Europa (zomertijd))

But now it's outputting something like this: 2015-04-13T20:15:18.322Z

I had a script that was depending on the first format so it broke while nothing changed in my code. That's why I started investigating and found this as the problem.

I was wondering what's up with this. (I'm not asking for a formatting solution, just wondering why it's formatted like this)

Update 1: figured it might be useful to add version numbers of the browsers I tested (all with the same result).

  • Firefox developers edition: 39.0a2 (2015-04-07)
  • Iceweasel 31.4.0
  • Firefox 37.0.1

Update 2: Code example:

new Date();
-- output -- Date 2015-04-13T20:57:39.622Z

Turns out this is an UTC or Zulu time format. So now the question is: Why is it outputting a UTC date while it didn't do that before.


Solution

  • new Date() returns a date object. The console in Firefox helps you as a developer to debug things, and Mozilla may have changed the representation of an object in the console. Maybe they first just showed the date the object represented, and now they show a representation of the object that you can explore (there's a triangle ▶ that you can click on which expands the representation and shows more properties of the object).

    It shouldn't matter for the behavior of your programs. When you output a date on a page, you would not directly print the object, but convert it to a string for example, which you get in the case of new Date().toString(). This behavior won't likely just change for no reason.