difference between the new date ("2017-01-01") and the new date ("2017-1-1")
new Date("2017-01-01") is in the specification (see below for more details). new Date("2017-1-1") not, and therefore returns to any "... implementation-specific heuristics or specific implementation date formats" that the JavaScript engine wants to apply. For example, you have no guarantee of how (or will) it will be successfully disassembled, and if so, whether it will be analyzed as UTC or local time.
Although the new Date("2017-01-01") is in the specification, unfortunately what browsers should do with it, it was a moving target because it does not have a time zone indicator:
- In ES5 (December 2009), strings without a time zone indicator should be parsed as UTC. But unlike the ISO-8601 standard, the date and time format is based, which says that strings without a time zone indicator are for local time, and not for UTC. Thus, in ES5,
new Date("2017-01-01") parsed in UTC. - In ES2015 (aka ES6, June 2015), strings without a time zone indicator should have been local time, not UTC, for example, ISO -8601. So, in ES2015,
new Date("2017-01-01") parsed as local time. - But , which was again changed in ES2016 (June 2016), because browsers only analyzed form dates with
- in them like UTC for many years. So, as in ES2016, date-only formats (for example, "2017-01-01" ) are parsed in UTC, but date / time forms (for example, "2017-01-01T00:00:00" ) are parsed locally time.
Unfortunately, not all JavaScript engines currently implement the specification. Chrome (starting with this entry, v56) parses UTC date / time forms, although they should be local (just like IE9). But Chrome, Firefox and IE11 (I don't have IE10 or Edge), all date formats are processed only (in UTC format). IE8 does not implement the ISO-8601 form at all (was released before the release of the ES5 specification).
TJ Crowder Mar 28 '17 at 3:47 on 2017-03-28 03:47
source share