javascript从年,月,日创建日期 [英] javascript create date from year, month, day
本文介绍了javascript从年,月,日创建日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 javascript
中创建一个新的日期
。
I am trying to create a new date
in javascript
.
我有年
,月
和天
。在此教程之后,创建新日期的语法
应该是:
I have year
, month
and day
. Following this tutorial, syntax for creating new date
should be:
new Date(year, month, day, hours, minutes, seconds, milliseconds)
这正是我在做的事情:
var d = new Date(2016, 12, 17, 0, 0, 0, 0);
这应该是2016年12月17日,但在我的控制台输出中我看到:
This should be december 17th 2016, but in my console output I see:
Tue Jan 17 2017 00:00:00 GMT+0100 (Central Europe Standard Time)
我做错了什么?
推荐答案
根据 MDN - 日期:
月
表示月份的整数值,从
开始为0 12月的1月到11日。
Integer value representing the month, beginning with 0 for January to 11 for December.
你应该从你的月中减去1。
You should subtract 1 from your month.
这篇关于javascript从年,月,日创建日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文