Looks like the first example is parsing the date string as if it's in UTC (4 hours away from your local timezone?) and then when you print it it gets converted back.
The second format is parsed assuming it's in your local timezone, so midnight local time and printed the same.
Without a format specified, JavaScript has make guesses based on the string it's given. It's making a different choice for those two strings.
It thinks you mean 2018-04-30 UTC
in the first case, and when it prints back in your local timezone it's four hours earlier than the second case which it thinks is 2018-04-30 UTC-4
.
There's a note on MDN about avoiding parsing date/time strings using the Date
constructor and the Date.parse
function because of this ambiguity, you may get different behaviour across different browsers.