问题描述
有人知道为什么使用JavaScript Date对时间戳整数进行跟踪吗?如果我使用整数 -2500938981 转置为YYYY-MM-DD hh:mm:ss,则会得到 1890-09-30 22:43:59 。然后对于 -2500938980 ,我希望时间戳为 1890-09-30 22:44:00 。但实际上我得到的是 1890-09-30 22:43:40
db.collection.update({
id: 1/**customer id*/
},{
"$set": {
"environment.$[element]": {
"clusterId": 4,/**environment object with updated clusterId*/
"clusterName": "asd"/**environment object with updated clusterName*/
}
}
},{
arrayFilters: [
{
"element.clusterid": 6/**clusterId of environment you have to update*/
}
]
})
也在此处进行了测试:https://www.w3schools.com/code/tryit.asp?filename=GK1UBRVKDS91
此外,也在https://www.freeformatter.com/epoch-timestamp-to-date-converter.html上进行了测试,发生了以下情况:
var datetime1 = new Date((-2500938981) * 1000)
var datetime2 = new Date((-2500938980) * 1000)
// dt1 in YYYY-MM-DD hh:mm:ss is 1890-9-30 22:43:59
var dt1 = datetime1.getFullYear() + "-" + (datetime1.getUTCMonth() + 1) + "-" + datetime1.getUTCDate() +
" " + datetime1.getUTCHours() + ":" + datetime1.getUTCMinutes() + ":" + datetime1.getSeconds();
// dt1 in YYYY-MM-DD hh:mm:ss is 1890-9-30 22:43:40
var dt2 = datetime2.getFullYear() + "-" + (datetime2.getUTCMonth() + 1) + "-" + datetime2.getUTCDate() +
" " + datetime2.getUTCHours() + ":" + datetime2.getUTCMinutes() + ":" + datetime2.getSeconds();
console.log(dt1)
console.log(dt2)
在https://www.epochconverter.com/上可以正常运行:
-2500938981 -> 9/30/1890,11:59:59 PM
-2500938980 -> 9/30/1890,11:43:40 PM
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)