LENTON'S BLOG

JavaScript中Date对象取值month为什么是从0开始

在JavaScript中,Date对象的getMonth()方法返回的月份需要+1,如取当前月份:var oDate = new Date(); console.log( oDate.getMonth()+1 );//取当前月份,需要加1 console.log( oDate.getFullYear() );//取当前年份,不需要加1 console.log( oDate.getDate() 
2018-09-05 17:09:56 4108 2