문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top