美文网首页
nodejs new Date() 获取的时间与系统时间不一致

nodejs new Date() 获取的时间与系统时间不一致

作者: UU5209966 | 来源:发表于2020-10-14 17:09 被阅读0次

https://github.com/nodejs/node/issues/29900

Issues

Inconsistent Date.prototype.getTime() value across different Node.js versions

Reason

The date is formatted by V8 and the ICU libraries and they receive occasional updates that may change the output. Importantly, the embedded timezone database is updated every few months.

I'm going to close this out because it's not under the control of Node.js but thanks anyway for the report.

// nodejs同步服务器时间时,避免使用new Date()转换时间后再设置系统时间
// 如果返回的是时间戳使用date命令sudo date -s @1577808000
// 如果返回的是字符串使用date命令sudo date -s '2020-01-01 00:00:00'

var ntpTime = parseInt(timestmap_ms / 1000);
var mExec = "sudo date -s @" + ntpTime + " && sudo hwclock --systohc";
exec(mExec, function (err, stdout, stderr) {
      if (err) {
        console.log('exec error' + err);
      } 
 });

相关文章

网友评论

      本文标题:nodejs new Date() 获取的时间与系统时间不一致

      本文链接:https://www.haomeiwen.com/subject/bldwpktx.html