export function getDate() { const date = new Date() const year = date.getFullYear() let month = date.getMonth() + 1 let day = date.getDate() if (month < 10) { month = '0' + month } if (day < 10) { day = '0' + day } return year + '-' + month + '-' + day } export function formatDate(date) { const year = date.getFullYear() let month = date.getMonth() + 1 let day = date.getDate() if (month < 10) { month = '0' + month } if (day < 10) { day = '0' + day } return year + '-' + month + '-' + day } export function getOneMonthOffset() { const myDate = new Date() let year = myDate.getFullYear() let month = myDate.getMonth() let date = myDate.getDate() let end = year + '-' + ('0' + (month + 1)).slice(-2) + '-' + ('0' + date).slice(-2) if (month === 0) { year -= 1 month = 12 } else if (month === 2) { date = date > 28 ? 28 : date } else { date = date > 30 ? 30 : date } let start = year + '-' + ('0' + month).slice(-2) + '-' + ('0' + date).slice(-2) return { start, end } } export function getOneWeekOffset(start) { const weekAgo = new Date(start).getTime() + 7 * 24 * 3600 * 1000 const endDate = new Date(weekAgo) const year = endDate.getFullYear() const month = endDate.getMonth() + 1 const date = endDate.getDate() const end = year + '-' + ('0' + month).slice(-2) + '-' + ('0' + date).slice(-2) return { start, end } } export function getHourMinute() { const date = new Date() const hour = date.getHours() const min = date.getMinutes() return Number(hour + '' + ('0' + min).slice(-2)) } export function getTomorrow() { const tomorrow = new Date().getTime() + 24 * 3600 * 1000 return new Date(tomorrow) } export function getAWeekFromNow() { const weekAfter = new Date().getTime() + 7 * 24 * 3600 * 1000 return new Date(weekAfter) } export function getOneWeekText() { const day = new Date().getDay() const weeks = ['日', '一', '二', '三', '四', '五', '六'] const arr = new Array(7) for (let index = 0; index < 7; index++) { let tempDay = (day + index) % 7 arr[index] = weeks[tempDay] } return arr } export function getNextSevenDate() { const dates = new Array(7) for (let index = 0; index < dates.length; index++) { dates[index] = getDateByOffeset(index) } return dates } function getDateByOffeset(offset) { const date = new Date() date.setDate(date.getDate() + offset) //获取offset天后的日期 const year = date.getFullYear() let month = date.getMonth() + 1 //获取当前月份 month = month < 10 ? '0' + month : month let day = date.getDate() //获取当前月份的日期 day = day < 10 ? '0' + day : day return { fullDate: year + '-' + month + '-' + day, date: day, } } export function formatDatetime(date) { const year = date.getFullYear() let month = date.getMonth() + 1 let day = date.getDate() let hour = date.getHours() let minute = date.getMinutes() if (month < 10) { month = '0' + month } if (day < 10) { day = '0' + day } return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':00' } export function getDateTime() { const date = new Date() const year = date.getFullYear() let month = date.getMonth() + 1 let day = date.getDate() let hour = date.getHours() let minute = date.getMinutes() let second = date.getSeconds() return year + '-' + ('0' + month).slice(-2) + '-' + ('0' + day).slice(-2) + ' ' + ('0' + hour).slice(-2) + ':' + ('0' + minute).slice(-2) + ':' + ('0' + second).slice(-2) }