我有以下代码,
var x = new Date("2016-04-04T00:00:00").getTime();
console.log(x);
x
的输出在 Chrome 中为 1459728000000
,在 Firefox 中为 1459753200000
。
但我也想在 Firefox 中使用 Chrome 的输出 - 有解决方法吗?
最佳答案
当您未指定时区时,Chrome 默认为 UTC,而 Firefox 默认为您的系统时区。通过在您的时间后附加 Z
来指定您的意思是 UTC:
var x = new Date("2016-04-04T00:00:00Z").getTime();
关于javascript - 为什么 Date.prototype.getTime() 为 Chrome 和 Firefox 提供不同的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36440893/