I\'m trying to pass both date strings to new Date(t)
.
I expect both strings represent the same time, after all, if I omit the time, shouldn\'t it be mid
According to the specifications:
The function first attempts to parse the format of the String according to the rules called out in Date Time String Format (15.9.1.15). If the String does not conform to that format the function may fall back to any implementation-specific heuristics or implementation-specific date formats.
And Date Time String Formats accept 2016-02-16
as a valid date
This format includes date-only forms:
YYYY
YYYY-MM
YYYY-MM-DD[...] If the HH, mm, or ss fields are absent “00” is used as the value and the value of an absent sss field is “000”. The value of an absent time zone offset is “Z”.
Thus 2016-02-16
translates to 2016-02-16T00:00:00.000Z
.
The other date 2016-02-16 00:00
does not conform to the format and therefore its parsing is implementation specific. Apparently, such dates are treated as having local time zone and your example date will return different values depending on time zone:
/* tz = +05:00 */ new Date("2016-02-16 00:00").toISOString() // 2016-02-15T19:00:00.000Z
/* tz = -08:00 */ new Date("2016-02-16 00:00").toISOString() // 2016-02-16T08:00:00.000Z
Summary:
NaN
instead of trying to parse non-conforming dates. Just test your code in Internet Explorer 11 ;)