node.js - NodeJS服务器每小时获取时间戳

标签 node.js momentjs

有什么方法可以让我在运行 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/

相关文章:

node.js - gulp.src 使用同步 globbing

javascript - Selenium:滚动到页面末尾

javascript - Node - 无法在 VSCode 中编译 moment.js(模块和需求问题)

angular - 如何在 Moment js 中设置有效的空日期?

javascript - 如何使用 moment.js 解析给定的日期字符串?

javascript - 需要使用 moment js 的日期帮助(2015-06-02T00 :00:00Z)

node.js - 冲突的对等依赖项 : React Native for iOS

node.js - Highland.js 中的嵌套流操作

Eclipse+Node.js调试时报错: "Failed to connect to Standalone V8 VM connect timed out"

javascript - Moment.js 时区 - 输出时考虑处于不同时区的日期/时间