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);
}
});
网友评论