I am getting an odd behavior if I pass the Date constructor just a date string. Example:
<div>Date 1: <span id="mydate1"></span></div>
<div>Date 2: <span id="mydate2"></span></div>
<div>Date 3: <span id="mydate3"></span></div>
<script>
document.getElementById("mydate1").innerHTML = (new Date("2022-06-28 20:32:00")).toString();
document.getElementById("mydate2").innerHTML = (new Date("2022-06-28")).toString();
document.getElementById("mydate3").innerHTML = (new Date("2022-06-28 00:00:00")).toString();
</script>
This results in the following:
Date 1: Tue Jun 28 2022 20:32:00 GMT-0400 (Eastern Daylight Time)
Date 2: Mon Jun 27 2022 20:00:00 GMT-0400 (Eastern Daylight Time)
Date 3: Tue Jun 28 2022 00:00:00 GMT-0400 (Eastern Daylight Time)
Date 1 works as I would expect. But why are Date 2 and 3 different? With just a date string, it seems to be inferring the date is in UTC, where as with a time field it seems to assume it is in my locale time.
Any thoughts? I can work around it by appending the 00:00:00 text.