import dayjs from 'dayjs' export const formatData = (times, keys, format = 'YYYY-MM-DD') => { const data = {} if (times && times.length) { for (let i = 0; i < keys.length; i++) { data[keys[i]] = dayjs(times[i]).format(format) } } return data } export const getNowDateAndMonday=(time)=> { let timestamp = new Date(time.replace(/-/g, "/")).getTime(); let serverDate = new Date(time); if (serverDate.getDay() == 0) { timestamp -= 7 * 24 * 60 * 60 * 1000; } let mondayTime = timestamp - (serverDate.getDay() - 1) * 24 * 60 * 60 * 1000; let mondayData = new Date(mondayTime); //年 let mondayY = mondayData.getFullYear(); //月 let mondayM = mondayData.getMonth() + 1 < 10 ? "0" + (mondayData.getMonth() + 1) : mondayData.getMonth() + 1; //日 let mondayD = mondayData.getDate() < 10 ? "0" + mondayData.getDate() : mondayData.getDate(); let str = mondayY + "-" + mondayM + "-" + mondayD; return str; } export const getNowDateAndSunday=(time) =>{ let timestamp = new Date(time.replace(/-/g, "/")).getTime(); let serverDate = new Date(time); let num = 7 - serverDate.getDay(); if (num == 7) { num = 0; } let sundayTiem = timestamp + num * 24 * 60 * 60 * 1000; let SundayData = new Date(sundayTiem); //年 let tomorrowY = SundayData.getFullYear(); //月 let tomorrowM = SundayData.getMonth() + 1 < 10 ? "0" + (SundayData.getMonth() + 1) : SundayData.getMonth() + 1; //日 let tomorrowD = SundayData.getDate() < 10 ? "0" + SundayData.getDate() : SundayData.getDate(); let str = tomorrowY + "-" + tomorrowM + "-" + tomorrowD; return str; }