const log = console.log;
let old = Date.now();
let d = new Date(old)
let oa = [d.getFullYear(), d.getMonth(), d.getDate(), " ", d.getHours(), d.getMinutes(), d.getSeconds()];
log("old ", oa.join(":"));
setTimeout(function() {
let d = new Date();
let oa = [d.getFullYear(), d.getMonth(), d.getDate(), " ", d.getHours(), d.getMinutes(), d.getSeconds()];
log("new ", oa.join(":"));
}, 10000);
结果:
$ node for.js
old 2021:0:8: :16:18:26
new 2021:0:8: :16:18:36