var date1 = new Date('1900-01-01');
console.log(date1);
收率: “Mon Jan 01 1900 01:00:00 GMT + 0100(W. Europe Standard Time)”
var date2 = new Date(1900,1,1);
console.log(date2);
收率: “周二01年1月1日1900 00:00:00 GMT + 0100(欧洲标准时间)”
但我不明白为什么!
答案 0 :(得分:1)
您可以看到月份差异,因为当您将单个组件(年,月,日等)传递给Date
对象构造函数时,您必须考虑月份参数应以0
开头:
console.log( new Date('1900-01-01').getMonth() ); // 0
除了1月/ 2月之外,不应该有任何日期差异。
MDN: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date