以下代码(参见jsfiddle)
var dt = new Date("2016-02-28");
console.log(dt);
日志
Sat Feb 27 2016 19:00:00 GMT-0500 (Eastern Standard Time)
注释 27 与 28。我需要创建一个日期变量,但如何忽略时区?
更新:
这解决了我的问题:手动解析
var dt = new Date("2016-02-28");
console.log(dt);
var dt2 = new Date(2016,1,28);
console.log(dt2);
日志
Sat Feb 27 2016 19:00:00 GMT-0500 (Eastern Standard Time)
Sun Feb 28 2016 00:00:00 GMT-0500 (Eastern Standard Time)
最佳答案
如果您在 JS 中创建日期对象,则可以使用 toLocaleDateString()
方法,以便根据区域设置格式化日期
var dt = new Date("2016-02-28");
console.log(dt.toLocaleDateString());
输出
2/27/2016
关于javascript - 如何摆脱 Javascript 中的日期时区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36220320/