javascript - 如何在 Javascript 中将 UTC 日期构造为对象而不是数字?

标签 javascript date

在 Javascript 中,给定 d=new Date() 可能是 d.getHours()!=d.getUtcHours()

我可以构造一个 Date 对象,明确地给出组件

new Date (y, m, d, hrs, mins)

但如果这些组件是 UTC,那么我就有问题了。来自 the docs

The UTC() method differs from the Date constructor in two ways.

  • Date.UTC() uses universal time instead of the local time.

  • Date.UTC() returns a time value as a number instead of creating a Date object.

如何在给定 UTC 组件的情况下构建Date 对象

最佳答案

根据 this answer你可以这样做:

new Date(Date.UTC(year, month, day, hour, minute, second))

关于javascript - 如何在 Javascript 中将 UTC 日期构造为对象而不是数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39330401/

相关文章:

Perl - 如何转换日期?

PHP 日期到字符串的转换为每个结果增加一分钟

sql - 如何找出 postgresql 中两个参数之间的值?

R Lubridate 在给定两位数的年份时返回不需要的世纪

javascript - Node JS : Named callback functions and Garbage collection

javascript - 如何从无渲染类 React-Native 调用函数

javascript - 如何在保持本地日期的同时执行 date.toString?

javascript - 使用js ajax的参数调用c#方法

javascript - Sencha Touch ExtJS 添加复选框列表

jquery - 打开具有特定日期的日期选择器