今日 本月 本季度 本年
export function cycleTimeLinkage(type){ let date = new Date(); date.setDate(1); let month = parseInt(date.getMonth() + 1); //当前月 let day = date.getDate(); //今日 let currentMonth = date.getMonth(); let nextMonth = ++currentMonth; let nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1); let oneDay = 1000 * 60 * 60 * 24; let lastTime = new Date(nextMonthFirstDay - oneDay); let endMonth = parseInt(lastTime.getMonth() + 1); let endDay = lastTime.getDate(); let intime = []; if (type == 1) { intime.push(new Date(new Date(new Date().toLocaleDateString()).getTime())); intime.push(new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1)); return intime; } else if (type == 2) { //本月第一天与最后一天 intime.push( new Date(new Date(new Date(date.getFullYear() + "-" + month + "-" + day).toLocaleDateString()).getTime()) ); intime.push( new Date(new Date(new Date(date.getFullYear() + "-" + endMonth + "-" + endDay).toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1) ); return intime; } else if (type == 3) { //本季度第一月第一天与最后一月最后一天 if (month <= 3) { month = 1; } else if (month > 3 && month <= 6) { month = 4; } else if (month > 6 && month <= 9) { month = 7; } else if (month > 9) { month = 10; } if (endMonth <= 3) { endMonth = 3; } else if (endMonth > 3 && endMonth <= 6) { endMonth = 6; } else if (endMonth > 6 && endMonth <= 9) { endMonth = 9; } else if (endMonth > 9) { endMonth = 12; } let newEndDay = new Date(date.getFullYear(), endMonth, 0); //判断当前年当前月最后一天 intime.push( new Date(new Date(new Date(date.getFullYear() + "-" + month + "-" + day).toLocaleDateString()).getTime()) ); intime.push(new Date(new Date(newEndDay).getTime() + 24 * 60 * 60 * 1000 - 1)); return intime; } else if (type == 4) { //本年第一月第一天与最后一月最后一天 let yearEndDay = new Date(date.getFullYear(), 12, 0); intime.push( new Date(new Date(new Date(date.getFullYear() + "-" + "01" + "-" + "01").toLocaleDateString()).getTime()) ); intime.push(new Date(new Date(yearEndDay).getTime() + 24 * 60 * 60 * 1000 - 1)); return intime; } }