mounted() {
this.getMonthFirstLastDay('2022 - 03 - 16');
},
getMonthFirstLastDay(date) {
var date = new Date();
let year = date.getFullYear();
const month = date.getMonth() + 1;
var startDate = new Date(year + "/" + month + "/" + 1);
let nextMonth = month + 1;
if (nextMonth === 13) {
year += 1;
nextMonth = 1;
}
const dateLong =
new Date(year + "/" + nextMonth + "/" + 1).getTime() -
24 * 60 * 60 * 1000;
var endDate = new Date(dateLong);
startDate = day(startDate).format("YYYY-MM-DD 00:00:00");
endDate = day(endDate).format("YYYY-MM-DD 23:59:59");
console.log("startDate1", startDate);
console.log("endDate1", endDate);
}
import day from "dayjs";
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/25b899b2e3356760a244064362d98673.png)