学習目標:
学习目标
- [ ] 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.getFull Year(), today.getMonth(), 1) - 3. 当月の最終日
new Date(today.getFull Year(), today.getMonth() + 1, 0)