Heim > Fragen und Antworten > Hauptteil
P粉9165538952023-08-26 10:46:09
您可以使用以下代码获取一个月的天数:
const getDays = (year, month) => new Date(year, month, 0).getDate() const days = getDays(2021, 8) console.log(days)
P粉7926739582023-08-26 10:42:00
本月剩余天数
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);