大家好,我正在寻找一种以时间戳获取当前系统时间的方法。 我用它来获取时间戳:
new Date().getTime();
但它返回 UTC 时区的时间,而不是服务器使用的时区
有没有办法获取系统时区的时间戳?
最佳答案
查看 moment.js http://momentjs.com/
npm install -S moment
默认情况下,新时刻对象将具有系统时区偏移量。
var now = moment()
var formatted = now.format('YYYY-MM-DD HH:mm:ss Z')
console.log(formatted)
关于javascript获取系统时区的时间戳而不是UTC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16393326/