var currentDate = new Date(); var currentYear = currentDate.getFullYear(); var currentMonth = currentDate.getMonth(); var currentMonthLastDate = (new Date(currentYear, currentMonth, 0)).getDate(); var daysLeftInMonth = currentMonthLastDate - currentDate.getDate(); console.log(daysLeftInMonth);
您可以使用以下代码获取一个月的天数:
本月剩余天数