我有以下代码,
var x = new Date("2016-04-04T00:00:00").getTime();
console.log(x);
x
的输出在Chrome中为1459728000000
,在Firefox中为1459753200000
。但是我也想要Chrome在Firefox中的输出-有解决方法吗?
最佳答案
当您未指定时区时,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/