将 Javascript 当前日期时间转换为 UTC 日期时间(以毫秒为单位)

Convert Javascript current date time to UTC date time in milliseconds

我找不到将 Javascript 中的当前 date/time 转换为 UTC 中的完整日期时间的方法。我需要相当于

var now = new Date().getTime();

但是 returns 以毫秒为单位的 UTC 时间

类似这样的事情

var UTCnow = new Date().getUTCTime();

我似乎看不出我可以使用什么在 JS Date 对象中实现这一点。

如有任何帮助,我们将不胜感激。

根据 documentation:

The getTime() method returns the numeric value corresponding to the time for the specified date according to universal time.

getTime() always uses UTC for time representation. For example, a client browser in one timezone, getTime() will be the same as a client browser in any other timezone.

换句话说,它已经完成了您的要求。

你也可以做同样的事情而不实例化一个Date对象:

var utcnow = Date.now();

其中 the docs 描述为:

The Date.now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.