var thisDate = new Date();
console.log(thisDate);
console.log(thisDate.getMonth());
输出:
Thu May 14 2020 12:25:19 4
期望值为5
getMonth()
返回数字,从0到11,所以只需在其上加上+1。https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth
使用此代码
var thisDate = new Date();
console.log(thisDate);
console.log(thisDate.getMonth() + 1);