learning target:
学习目标
- [ ] vue gets the date of the first and last day of the month to which the current date belongs
Learning Content:
学习内容如下所示:
1. Use JavaScript’s Date object to get the first and last days of the month to which the current date belongs.
// 获取当前日期
const today = new Date();
// 获取当前月份的第一天
const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
// 获取下个月的第一天
const nextMonth = today.getMonth() === 11 ? 0 : today.getMonth() + 1;
const firstDayOfNextMonth = new Date(today.getFullYear(), nextMonth, 1);
// 获取当前月份的最后一天
const lastDayOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0);
// 获取上个月的最后一天
const lastDayOfLastMonth = new Date(today.getFullYear(), today.getMonth(), 0);
console.log(firstDayOfMonth);
console.log(lastDayOfMonth);
console.log(firstDayOfNextMonth);
console.log(lastDayOfLastMonth);
Knowledge summary:
提示:这里统计学习计划的总量
Summarize:
- 1. Get the current date
new Date() - 2. Get the first day of the current month
new Date(today.getFullYear(), today.getMonth(), 1) - 3. The last day of the current month
new Date(today.getFullYear(), today.getMonth() + 1, 0)