I try to get UTC Date. Why
(new Date("2015-04-22")).getUTCDate() = 22
And
(new Date("Apr 22, 2015")).getUTCDate() = 21
?
To quote MDN on the workings of Date.parse (called by new Date("string")):
Differences in assumed time zone
Given a date string of
"March 7, 2014",parse()assumes a local time zone, but given an ISO format such as"2014-03-07"it will assume a time zone of UTC. Therefore Date objects produced using those strings will represent different moments in time unless the system is set with a local time zone of UTC. This means that two date strings that appear equivalent may result in two different values depending on the format of the string that is being converted (this behavior is changed in ECMAScript ed 6 so that both will be treated as local).
Watch out for the warning I've highlighted on the last line
221989?2015-04-22is an universal format. ButApr 22, 2015is a local format.