在 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/