简体   繁体   English

Javascript日期没有任何意义

[英]Javascript Dates Not making any sense

How does this happen? 这是怎么发生的?

var d = new Date(2014, 0, 0, 0, 0 , 0, 0);   
assert(d.getTime()/1000 == 1388534400);     // somehow, this results in assert(1388466000 == 1388534400)

Why wouldn't d be Wed, Jan 1st, 2014 00:00:00 GMT, rather than Tue, 31 Dec 2013 05:00:00 GMT 为什么不会在格林尼治标准时间2014年1月1日星期三00:00:00,而不是格林尼治标准时间2013年12月31日星期二05:00:00

Day of month is numbered from 1, not 0. Day 0 of a month is the last day of the previous month. 一个月的天从1开始编号,而不是0。一个月的第0天是上个月的最后一天。

Also note that the API your using is going to construct a date in the local time zone. 另请注意,您使用的API将在本地时区构造日期。 Even if you construct a date for 1 Jan 2014, it will only look like midnight GMT on that date if your local time zone is GMT. 即使您将日期设置为2014年1月1日,但如果您的本地时区为格林尼治标准时间,则该日期只会看起来像该格林尼治标准时间。

Date is localized and follows the timezone of your local computer. Date已本地化,并遵循本地计算机的时区。 Apparently you're in a GMT+5 timezone, and as the other answer points out the day off is explained by the 1-based offset of days. 显然您处于格林尼治标准时间+5时区,正如其他答案指出的那样,放假时间由1的天数偏移量解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM