0

Given the following script with d3.js v4.10.2:

var parse_a_Date = d3.timeParse("%Y");
console.log(parse_a_Date('2017'));

Resulting output in Firefox:

Date 2016-12-31T23:00:00.000Z

Resulting output in Chrome:

Sun Jan 01 2017 00:00:00 GMT+0100 (Mitteleuropäische Zeit)

This makes me assume, that d3.js takes over the time zone setting of the browser. But if I get data from a CSV, I certainly don't want to have it falsified, just because the user's browser has a different time zone setting.

If my assumption about the browser time zone setting is correct, how can I avoid that this error happens?

Gerardo Furtado
  • 100,839
  • 9
  • 121
  • 171
Peter Szrama
  • 73
  • 1
  • 3
  • 1
    That's not an "error", and that has little to do with D3. Date parsing depends on the browser implementation, have a look here: https://stackoverflow.com/a/15110385/5768908 – Gerardo Furtado Sep 27 '17 at 00:47
  • 1
    Likely a duplicate of [*Why does Date.parse give incorrect results?*](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) BTW, both timestamps represent the same moment in time, it's just that they're formatted differently with different timezone offsets. Note that [*Date.prototype.toString*](http://ecma-international.org/ecma-262/8.0/#sec-date.prototype.tostring) is entirely implementation dependent, you can't guarantee the result. – RobG Sep 27 '17 at 00:58
  • "*…both timestamps represent the same moment in time…*"—that's the vital part! There is no difference in parsing, you are only witnessing a difference in the output. – altocumulus Sep 27 '17 at 08:05

0 Answers0