this.date = ''; let date = new Date(); switch (val) { case '本周': let WeekFirstDay = new Date(date - (date.getDay() - 1) * 86400000); let WeekLastDay = new Date((WeekFirstDay / 1000 + 6 * 86400) * 1000); let M = Number(WeekLastDay.getMonth()) + 1; this.starTime = WeekFirstDay.getFullYear() + "-" + M + "-" + WeekFirstDay.getDate(); //本周第一天日期 this.endTime = WeekLastDay.getFullYear() + "-" + M + "-" + WeekLastDay.getDate();//本周最后一天日期 break; case '本月': let MonthFirstDay = new Date(date.getFullYear(), date.getMonth(), 1); let MonthNextFirstDay = new Date(date.getFullYear(), date.getMonth() + 1, 1); let MonthLastDay = new Date(MonthNextFirstDay - 86400000); let m = Number(MonthFirstDay.getMonth()) + 1; if(m<10) m='0'+m; this.starTime = MonthFirstDay.getFullYear() + "-" + m + '-01'; // 本月第一天 this.endTime = MonthLastDay.getFullYear() + "-" + m + "-" + MonthLastDay.getDate(); //本月最后一天 break; case '上个月': let year = date.getFullYear(); let month = date.getMonth(); if (month === 0) { month = 12; year = year - 1; } if (month < 10) { month = '0' + month; } let myDate = new Date(year, month, 0); this.starTime = year + '-' + month + '-01'; //上个月第一天 this.endTime = year + '-' + month + '-' + myDate.getDate();//上个月最后一天 break; }
获取本周日期,本月日期,上个月日期
最新推荐文章于 2023-11-28 11:38:04 发布