Incorrect date shown in new Date() in JavaScript

前端 未结 3 392
不思量自难忘°
不思量自难忘° 2020-11-28 14:55

This is what I get in chrome console. I pass \"2016-09-05\"(YYYY-MM-DD) as the date and it shows me Sept 4,2016 as the date.

Another constructor shows the

3条回答
  •  日久生厌
    2020-11-28 15:14

    use setFullYear the syntax is Date.setFullYear(year,month,day)

    mydate = new Date();
    mydate.setFullYear(2016, 08, 05);
    

提交回复
热议问题