Maybe the answer is obvious, but I don\'t get it. Why are the Dates in the Code Snippet different? Does the format say something about the hours as well?
In some browsers, months or days with no leading zeroes may produce an error:
new Date("2017-2-9");
In consquent, that the behavior of the format "yyyy-mm-dd" is undefined.
Some browsers will try to guess the format, some will return NaN and some will return null.
That is why new Date("2017-02-09")
has Thu Feb 09 2017 01:00:00 GMT+0100 (Mitteleuropäische Zeit)
as output, because the behavior for this format is defined and it adds the timezone to the date. new Date("2017-2-9")
has Thu Feb 09 2017 00:00:00 GMT+0100 (Mitteleuropäische Zeit)
as output, because chrome trys to guess the format, but cannot add the timezone. In Safari in return null
.