为什么新的Date()函数在chrome和firefox中提供不同的输出

Tan*_*hah 4 javascript time date

我将这个新日期传递到Firefox和Chrome控制台(同一台计算机和时区),我得到了混合的结果.所以令人困惑......在chrome new Date(); // Wed Dec 09 2015 18:06:55 GMT + 0530(IST)

在firefox中新建Date(); //日期2015-12-09T12:36:34.410Z

Ale*_*exD 8

您的困惑是由不同的时区显示引起的.

您的Chrome为您提供UTC + 0的时间,而Firefox则为您提供GMT + 0530的时间.

您可以通过写入指定您希望两者始终为UTC

var myDate = new Date();
myDate.toISOString() // will give you a date in the format you see by Chrome
Run Code Online (Sandbox Code Playgroud)