学习目标:
学习目标
- [ ] vue 获取当前日期所属月的第一天和最后一天的日期
学习内容:
学习内容如下所示:
1. 使用 JavaScript 的 Date 对象来获取当前日期所属月的第一天和最后一天的日期
// 获取当前日期
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);
知识小结:
提示:这里统计学习计划的总量
总结:
- 1、获取当前日期
new Date() - 2、获取当前月份的第一天
new Date(today.getFullYear(), today.getMonth(), 1) - 3、当前月份的最后一天
new Date(today.getFullYear(), today.getMonth() + 1, 0)