This SO post addresses why JavaScript Date constructors can be one day off, but we're seeing output that doesn't account for time zone changes, i.e., it's showing midnight in our time zone (PST).
Any clue what's happening? Ultimately, we want to get the date (no time) in the user's local time zone, add X days, write this new date to localStorage
, then fetch the new date. Right now, what we fetch from localStorage
is one day behind because of the issue below.
var test = new Date( "Sun Dec 29 2013" )
Sat Dec 28 2013 00:00:00 GMT-0800 (Pacific Standard Time)
Here's a little more detail based on the comments:
var date = new Date();
var dateAsString = date.toDateString();
console.log(new Date(dateAsString));