有些浏览器将部分日期字符串解析为UTC,有些则解析为本地时间,
因此,当您阅读它时,本地化时间可能因浏览器而异
按时区偏移量.
您可以强制Date为UTC并添加本地偏移量
希望时间得到保证:
1. set UTC time:
var D= new Date("2015-02-01"+'T00:00:00Z');
2. adjust for local:
D.setMinutes(D.getMinutes()+D.getTimezoneOffset());
D的值:(本地日期)
Sun Feb 01 2015 00:00:00 GMT-0500(东部标准时间)
抵消将是当地时间.
Some differences between browsers when time zone is not specified in a parsed string:
(tested on Eastern Standard Time location)
(new Date("2015-02-01T00:00:00")).toUTCString();
Firefox 35: Sun, 01 Feb 2015 05:00:00 GMT
Chrome 40: Sun, 01 Feb 2015 00:00:00 GMT
Opera 27: Sun, 01 Feb 2015 00:00:00 GMT
IE 11: Sun, 01 Feb 2015 05:00:00 GMT
IE and Firefox set the Date as if it was local, Chrome and Opera as if it was UTC.