3 ms·
This mistake is quite easy to make in JavaScript. Dates are internally milliseconds since epoch but if you construct a date by giving year, month, day, you get
by dan-robertson 8y ago
This mistake is quite easy to make in JavaScript. Dates are internally milliseconds since epoch but if you construct a date by giving year, month, day, you get midnight in the local timezone which may well be on a different day from midnight in UTC, so if you send back a unix timestamp or (trying to be clever) use UTC functions to get a date from a Date object, you may likely get an off by one error.
- mediumdeviation 8y agoAnother consequence of this is that JS Date objects don't understand the concept of timezones, and only allows you to output dates in either the client timezone or UTC. This makes it extremely hard to, for example, display the arrival time of a flight in the destination timezone. Intl.DateTimeFormat[1] is a godsend for this. [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...