/** * 根据指定时间去返回天数 * @param start 开始时间 * @param end 结束时间 * @returns {number} 天数 */ function tmpTDiff (start, end) { const d1 = Date.parse(new Date(start)) const d2 = Date.parse(new Date(end)) // 时间戳相减 / 天数 const day = parseInt((d2 - d1) / (1000 * 60 * 60 * 24)) return day } /** * 获取多少月前的时间 * @param num 多少月 * @returns {string} yyyy-MM-dd 00:00:00 */ function getSpecifyMonthDate (num) { const timeCount = new Date().getTime() - num * 30 * 24 * 60 * 60 * 1000 const date = new Date(timeCount) return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} 00:00:00` } /** * 获取多少月前的时间 * @param num 多少月 * @returns {string} yyyy-MM-dd 00:00:00 */ function getSpecifyDayDate (day) { const timeCount = new Date().getTime() - day * 24 * 60 * 60 * 1000 const date = new Date(timeCount) return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} 00:00:00` } /** * 获取今天最后日期 * @returns {string} yyyy-MM-dd 23:59:59 */ function getDayLast () { const date = new Date() const year = date.getFullYear() const month = date.getMonth() + 1 const strDate = date.getDate() - 1 return `${year}-${month}-${strDate} 23:59:59` } export default { tmpTDiff, getSpecifyMonthDate, getSpecifyDayDate, getDayLast }