示例代码:
var currentDate = new Date();
var currentMonth = currentDate.getMonth() + 1;
console.log(currentMonth);
示例代码:
var currentDate = new Date();
var currentMonth = currentDate.toLocaleString().match(/(\d{1,2})\/\d{1,2}\/\d{4}/)[1];
console.log(currentMonth);
示例代码:
var currentMonth = moment().month() + 1;
console.log(currentMonth);
以上是三种常用的方法,可以根据实际需要选择适合的方法来获取当前月份。