import dayjs from 'dayjs'; export function getNowDateAndMonday(time: number) { let timestamp = time; const serverDate = new Date(time); if (serverDate.getDay() == 0) { timestamp -= 7 * 24 * 60 * 60 * 1000; } const mondayTime = timestamp - (serverDate.getDay() - 1) * 24 * 60 * 60 * 1000; const mondayData = new Date(mondayTime).getTime(); //年 // const mondayY = mondayData.getFullYear(); // //月 // const mondayM = // mondayData.getMonth() + 1 < 10 // ? '0' + (mondayData.getMonth() + 1) // : mondayData.getMonth() + 1; // //日 // const mondayD = // mondayData.getDate() < 10 // ? '0' + mondayData.getDate() // : mondayData.getDate(); // const str = mondayY + '-' + mondayM + '-' + mondayD; return mondayData; } export function getNowDateAndSunday(time: number) { const timestamp = time; const serverDate = new Date(time); let num = 7 - serverDate.getDay(); if (num == 7) { num = 0; } const sundayTiem = timestamp + num * 24 * 60 * 60 * 1000; const SundayData = new Date(sundayTiem).getTime(); //年 // const tomorrowY = SundayData.getFullYear(); //月 // const tomorrowM = // SundayData.getMonth() + 1 < 10 // ? '0' + (SundayData.getMonth() + 1) // : SundayData.getMonth() + 1; // //日 // const tomorrowD = // SundayData.getDate() < 10 // ? '0' + SundayData.getDate() // : SundayData.getDate(); // const str = tomorrowY + '-' + tomorrowM + '-' + tomorrowD; return SundayData; } export const getTimes = ( times: any, keys: Array = [], format = 'YYYY-MM-DD' ) => { if (times && times.length) { return format == 'YYYY-MM-DD' ? { [keys[0] || 'start']: dayjs(times[0]).isValid() ? dayjs(times[0]).format(format) + ' 00:00:00' : '', [keys[1] || 'end']: dayjs(times[1]).isValid() ? dayjs(times[1]).format(format) + ' 23:59:59' : '' } : { [keys[0] || 'start']: dayjs(times[0]).isValid() ? dayjs(times[0]).format(format) : '', [keys[1] || 'end']: dayjs(times[1]).isValid() ? dayjs(times[1]).format(format) : '' }; } return {}; }; export function formatTime(time: number) { const hours = Math.floor(time / 3600); const minutes = Math.floor(Math.floor(time % 3600) / 60); const seconds = Math.floor(time % 60); const h = hours.toString().length === 1 ? `0${hours}` : hours; const m = minutes.toString().length === 1 ? `0${minutes}` : minutes; const s = seconds.toString().length === 1 ? `0${seconds}` : seconds; return `${h} 小时 ${m} 分钟 ${s} 秒`; }