function getDaysInCurrentMonth() {
const currentDate = new Date(); // Get current date
const currentYear = currentDate.getFullYear(); // Get current year
const currentMonth = currentDate.getMonth(); // Get current month
const firstDayOfMonth = new Date(currentYear, currentMonth, 1); // First day of the month
const lastDayOfMonth = new Date(currentYear, currentMonth + 1, 0); // Last day of the month
const totalDays = lastDayOfMonth.getDate(); // Get number of days in the current month
const dateRange = [];
for (let day = 1; day <= totalDays; day++) {
const date = new Date(currentYear, currentMonth, day);
dateRange.push(date);
}
return dateRange;
}
const daysInCurrentMonth = getDaysInCurrentMonth();
console.log("Date range in the current month:", daysInCurrentMonth);
06-15
2597
2597
11-07
09-01
8253
8253

被折叠的 条评论
为什么被折叠?



