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);