JavaScript-Date(),new Date()和ISODate之间的区别 [英] JavaScript - difference between Date(), new Date(), and ISODate
问题描述
我看到过这个问题的各种版本,但是没有一个能满足我的需求。
I've seen various versions of this question, but none of them answer my needs.
我想为MongoDB创建一个ISODate,并且正在使用Node .js。
I want to create an ISODate for MongoDB and I'm using Node.js.
在Node中,当我这样做时:
In Node, when I do:
console.log(Date());
我得到:
2016年9月26日星期一15:17:04 GMT-0400(EDT)<-这是正确的。
当我这样做时:
console.log(new Date());
我得到:
2016-09-26T19:17:04.731Z <-这是4个小时
我对执行ISODATE的方式的理解是:
My understanding of the way to do ISODATE is:
var isodate = new Date().toISOString()
console.log(isodate);
哪个收益率比 now提前4小时。
Which yields a time 4 hours ahead of "now".
我的系统日期正确。
我在这台不同的机器上运行,并且得到相同的结果。
My system date is correct. I run this one different machines, and I get the same results.
有人可以解释一下我为什么会及时出现差异吗?
Can someone please explain why I'm getting a discrepancy in time?
推荐答案
区别在于 2016-09-26T19:17:04.731Z
相关到格林尼治标准时间0时区和星期一2016年9月26日15:17:04 GMT-0400(EDT)
到您当地的时区。两者都指向同一时间:)
The difference is that 2016-09-26T19:17:04.731Z
related to GMT0 timezone and Mon Sep 26 2016 15:17:04 GMT-0400 (EDT)
to your local timezone. Both are point to the same time :)
您可以在 Wiki
这篇关于JavaScript-Date(),new Date()和ISODate之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!