1

Paying with new Date().toISOString(), I observe an inconsistency in parsing of the same date in different string formats: 2020-01-01 and 2020/01/01:

const opt1 = new Date("2020-01-01").toISOString();
document.write(`"2020-01-01": <b>${opt1}</b>`);

document.write("<br />");

const opt2 = new Date("2020/01/01").toISOString();
document.write(`"2020/01/01": <b>${opt2}</b>`);

I'm just curious, why 2020-01-01 and 2020/01/01 are parsed differently?

Mike
  • 14,010
  • 29
  • 101
  • 161
  • 1
    One of them is in GMT, the other is in the local timezone. – Barmar Apr 28 '20 at 18:55
  • @HereticMonkey, great, that's even more detailed explanation with a short leap in a JS-history. – Mike Apr 28 '20 at 19:04
  • 1
    If you want to know why YYYY-MM-DD is treated as UTC, the answer is in the TC39 deliberations recorded [here](https://github.com/tc39/ecma262/issues/87). Short answer: commercial interests won over common sense. – RobG Apr 28 '20 at 20:12

0 Answers0