javascript date creation, can't set the correct month

前端 未结 3 1914
天命终不由人
天命终不由人 2020-12-12 00:45
var d = new Date(2011,1,1);

alert(d);

this alert says February, while it should say January

anybody has some explanation for that ?

3条回答
  •  既然无缘
    2020-12-12 01:23

    The month argument is 0 based so you should pass 0 for January.

    var d = new Date(2011, 0, 1);
    

提交回复
热议问题