Reputation: 4488
So I'm using this to try to get the day before today. This works fine in Chrome but IE thinks its the day before that. My current system date is 09/05/2014 10:14 (PST).
var todaysDate = new Date();
var maxDate = new Date(Date.UTC(todaysDate.getFullYear(),todaysDate.getMonth(),todaysDate.getDate()-1));
Its worth mentioning that both IE and Chrome return the value 9 for the following.
console.log(todaysDate.getDate());
So if today = 09/05/2014 (PST)
Chrome gets 08/05/2014
IE gets 07/05/2014
What's going on? Why is IE interpreting this differently to Chrome?
Upvotes: 4
Views: 1213
Reputation: 324630
It's a timezone issue - timezones behind GMT will be pushed back a day by your code.
Try setting the "hours" to 12
. This will ensure that all timezones are on the same day.
So apparently UTC+14 is a thing. Try todaysDate.getUTC*
methods instead and be sure to include the hours/minutes/seconds.
Upvotes: 3