如何获取当前日期和时间作为常量?
我试图在应用程序首次加载时获取当前日期和时间作为全局常量变量。然后使用这个常量变量来调用 GET 方法。
在JS中有没有办法做到这一点?
我试过:
const time = moment().format("MMMM DD YYYY, hh:mm:ss");
I am trying to get the current date and time as a global constant variable when the app first load. Then use this constant variable to call GET method.
Is there a way to do this in JS?
I tried:
const time = moment().format("MMMM DD YYYY, hh:mm:ss");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的常量应该在页面加载时初始化,而不是在http请求上初始化
您应该将值存储在变量中,而不是在执行http请求时回忆moment()
your constant should be initialize at the loading of the page and not on the http request
you should store the value in a variable and not recall moment() when you perform your http request