Incorrect date shown in new Date() in JavaScript

enter image description here

This is what I get in chrome console. I pass "2016-09-05"(YYYY-MM-DD) as the date and it shows me Sept 4,2016 as the date.

Another constructor shows the right date

enter image description here

Passing it comma separated needs some tokenizing + parsing + making month zero indexed which I want to avoid


Solution 1:

If you omit the time in the new Date(string) constructor, UTC time is assumed. So the displayed value is actually correct. Use new Date('2016-09-05 00:00') to create the date object in local time.