0

Looking for clarification on this issue.

I found the date format ("yyyy-mm-dd"), returning a date that is 1 day previous.

new Date ("2018-05-13");
> Sat May 12 2018 17:00:00 GMT-0700 (PDT)

I confirmed that the date format ("mm-dd-yyyy") and ("yyyy-mm-dd 00:00:00") return the correct date.

new Date ("05-13-2018");
> Sun May 13 2018 00:00:00 GMT-0700 (PDT)

new Date ("2018-05-13 00:00:00");
> Sun May 13 2018 00:00:00 GMT-0700 (PDT)

I tested this in Chrome and FireFox.

Chrome has the error, Firefox does not. In addition Firefox dislikes the date format ("mm-dd-yyyy").

So, bugs?

E Net Arch
  • 458
  • 5
  • 13
  • Not bugs, Date parsing in browsers is such a minefield - read the [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) and use a library :p – Jaromanda X May 19 '18 at 02:05
  • 1
    the long dates are parsed w/locale, assuming PC's timezone, whereas the short date is parsed as GMT; you're in the midwest or east-coast of the US right? (GMT-5) So, Midnight on that date in England is 7pm local for you on the night before. Browsers make a good effort to recover data from many formats, but if you want a guarantee, then you have to use one of the Date output flavors like GMT or ISO. – dandavis May 19 '18 at 02:08
  • @dandavis you should put that as the answer, nice one. – Stuart May 19 '18 at 03:27
  • The short answer is that "yyyy-mm-dd" is the ISO 8601 date–only format and is required to be parsed as UTC by ECMA-262 (contrary to ISO 8601). Parsing of any other (non-ISO 8601) format is implementation dependent and generally treated as local or invalid. ECMAScript 2019 will introduce two more formats that must be parsed (the ones defined for [*toISOString*](https://tc39.github.io/ecma262/#sec-date.prototype.toisostring) and [*Date.prototype.toString*](https://tc39.github.io/ecma262/#sec-date.prototype.tostring)). – RobG May 19 '18 at 08:32

0 Answers0