有什么方法可以让我在运行 NodeJS 服务器后每小时获取时间戳吗?
因为启动服务器后,变量new Date()不会更新。
有什么想法吗?
最佳答案
Because after starting the server, the variable new Date() won't update.
我不完全确定您的用例,并且您没有提供任何代码,因此很难准确地知道您在做什么。
您始终可以再次执行new Date()
,以获取当前时间的新日期。或者如果您想要时间戳,只需执行 Date.now()
即可。只需将它与 setInterval
结合起来,你就应该是黄金了
setInterval(() => console.log(Date.now()), 3600 * 1000)
关于node.js - NodeJS服务器每小时获取时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49203345/