In my Java Script app I have the date stored in a format like so:
2011-09-24
Now when I try using the above value to create a new Date obje
I encountered this exact problem where my client was on Atlantic Standard Time. The date value the client retrieved was "2018-11-23" and when the code passed it into new Date("2018-11-23")
the output for the client was for the previous day. I created a utility function as shown in the snippet that normalized the date, giving the client the expected date.
date.setMinutes(date.getMinutes() + date.getTimezoneOffset());
var normalizeDate = function(date) {
date.setMinutes(date.getMinutes() + date.getTimezoneOffset());
return date;
};
var date = new Date("2018-11-23");
document.getElementById("default").textContent = date;
document.getElementById("normalized").textContent = normalizeDate(date);
Calling new Date("2018-11-23")