如何在NodeJS中获取UTC日期对象? [英] How to get UTC Date object in NodeJS?

查看:58
本文介绍了如何在NodeJS中获取UTC日期对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取UTC中的Current Date对象,然后使用Mongoose将其存储.

I want to get the Current Date object in UTC and then store it using Mongoose.

我尝试使用 new Date() Date.now()等.但是所有这些都返回本地时间.如何获取UTC日期对象?

I tried using new Date(), Date.now() etc. But all these returns local time. How do I get the UTC date object?

我想要Date对象,而不是字符串表示形式.

I want the Date object, not string representation.

推荐答案

只需使用 new Date(new Date().toUTCString())

转换为UTC后,如果需要日期对象,我们必须再次将其转换为日期对象.

After converting to UTC, we have to again convert it into Date object if we need a Date Object.

这篇关于如何在NodeJS中获取UTC日期对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆