dealDate:日期处理(type类型,date日期)
const moment = require('moment'); if (type === "0") { return date + " 00:00:00#" + date + " 23:59:59"; } else if (type === "1") { let now = new Date(date); let nowDayOfWeek = now.getDay(); // 本周的第几天 let nowDay = now.getDate(); // 当前日 // let nowMonth = date.substring(date.indexOf('-'), date.lastIndexOf('-')); // 当前月 let nowMonth = now.getMonth(); // 当前月 let nowYear = now.getYear(); // 当前年 nowYear += (nowYear < 2000) ? 1900 : 0; let weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek + 1); let weekEndDate = new Date(nowYear, nowMonth, nowDay + (7 - nowDayOfWeek)); return moment(weekStartDate).toISOString().substring(0, 10) + " 00:00:00#" + moment(weekEndDate).toISOString().substring(0, 10) + " 23:59:59"; } else if (type === "2") { let now = new Date(date); let nowMonth = now.getMonth(); // 当前月 let nowYear = now.getYear(); // 当前年 nowYear += (nowYear < 2000) ? 1900 : 0; //获得本月的开始时间 let monthStartDate = new Date(nowYear, nowMonth, 2); //获得本月天数 let monthEnd = new Date(nowYear, nowMonth + 1, 3); let days = (monthEnd - monthStartDate) / (1000 * 60 * 60 * 24); //获得本月的结束时间 let monthEndDate = new Date(nowYear, nowMonth, days); return moment(monthStartDate).toISOString().substring(0, 10) + " 00:00:00#" + moment(monthEndDate).toISOString().substring(0, 10) + " 23:59:59"; } else if (type === "3") { let now = new Date(date); let nowMonth = now.getMonth(); // 当前月 let nowYear = now.getYear(); // 当前年 nowYear += (nowYear < 2000) ? 1900 : 0; let m = 0; console.log('nowMonth', nowMonth); if (nowMonth < 3) {//012 m = 0; } else if (2 < nowMonth && nowMonth < 6) {//345 m = 3; } else if (5 < nowMonth && nowMonth < 9) {//678 m = 6; } else if (nowMonth >= 9) { //9 10 11 m = 9; } let quarterStartDate = new Date(nowYear, m, 2); let quarterEndDate = new Date(nowYear, (m === 9 ? 0 : m + 3), 2).getTime() - (60 * 60 * 24 * 1000); return moment(quarterStartDate).toISOString().substring(0, 10) + " 00:00:00#" + moment(new Date(Number(quarterEndDate))).toISOString().substring(0, 10) + " 23:59:59"; } else if (type === "4") { let now = new Date(date); let nowYear = now.getYear(); // 当前年 nowYear += (nowYear < 2000) ? 1900 : 0; return nowYear + "-01-01 00:00:00#" + nowYear + "-12-31 23:59:59"; }
type类型
[ { value:"0", desp:"日报表" }, { value:"1", desp:"周报表" }, { value:"2", desp:"月报表" }, { value:"3", desp:"季报表" }, { value:"4", desp:"年报表" } ]
date日期
2022-09-25
标签:00,vue,起始,选中,new,let,nowMonth,now,nowYear From: https://www.cnblogs.com/ZhaoHS/p/16730338.html