【发布时间】:2017-11-07 10:57:40
【问题描述】:
我正在尝试将毫秒转换为 UTC 日期对象,如下所示 -
var tempDate = new Date(1465171200000);
// --> tempDate = Mon Jun 06 2016 05:30:00 **GMT+0530 (India Standard Time)** {}
var _utcDate = new Date(tempDate.getUTCFullYear(), tempDate.getUTCMonth(), tempDate.getUTCDate(), tempDate.getUTCHours(), tempDate.getUTCMinutes(), tempDate.getUTCSeconds());
//--> _utcDate = Mon Jun 06 2016 00:00:00 **GMT+0530 (India Standard Time)** {}
时间正在重置为 UTC 时间,但时区仍为 GMT+0530(印度标准时间)。 是否有任何确定的方法可以将毫秒转换为具有 UTC 时区的 UTC 日期对象?
【问题讨论】:
-
你为什么要制作两个日期对象?要获取 UTC 日期字符串,请使用
tempDate.toUTCString() -
@evolutionxbox - 实际上 tempDate.toUTCString() 将日期对象转换为字符串,将无法对其进行进一步的日期操作。
标签: javascript date utc milliseconds gmt