Javascript date 01/01/0001

后端 未结 5 1267
慢半拍i
慢半拍i 2020-12-24 05:46

I want to create a Date object in javascript, which represents the year 0001, 2014 years ago.

I tried with

d = new Date(); d.setYear(1);
console.log         


        
5条回答
  •  半阙折子戏
    2020-12-24 06:14

    when handling JavaScript date objects you have to specify the full year for ex, 1950 and not 50. It is mentioned in the doc. So the code should be as Daniel has said also,

    d = new Date(); d.setFullYear(1);
    console.log(d);
    

提交回复
热议问题