如何通过 moment.js 显示 GMT 时间戳

问题描述 投票:0回答:1

我需要通过 moment.js 获取 UTC 时间戳,我编写的代码如下所示

const 时间戳 = moment().utc().unix(); 控制台日志(时间戳);

但是没用,显示的是本地时间,moment.js的文档也说如果我用unix()会在本地模式下创建。

如果我想在不支持额外功能的情况下以时间戳显示 UTC 时间,我该怎么做?

node.js momentjs
1个回答
0
投票

为什么要用moment?只需使用内置的日期对象

let date = new Date();
console.log(date.toUTCString());

© www.soinside.com 2019 - 2024. All rights reserved.