export default { // 获取当前时间 (YY-MM-DD) getNowFormatDay() { var date = new Date() var seperator1 = '-' var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1 var strDate = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate return currentdate }, // 获取当前时间 (YY-MM) getNowMonth() { var date = new Date() var seperator1 = '-' var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1 var currentdate = date.getFullYear() + seperator1 + month return currentdate }, // 获取上月当前时间 (YY-MM-DD) getBeforeFormatDay() { var date = new Date() var seperator1 = '-' var month = date.getMonth() < 10 ? '0' + date.getMonth() : date.getMonth() var strDate = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate return currentdate }, // 获取上月当前时间 (YY-MM) getBeforeMonth() { var date = new Date() var seperator1 = '-' var month = date.getMonth() < 10 ? '0' + date.getMonth() : date.getMonth() var currentdate = date.getFullYear() + seperator1 + month return currentdate }, // 获取当前时间 (YY-MM-DD hh:mm:ss) getNowFormatDate() { var date = new Date() var seperator1 = '-' var seperator2 = ':' var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1 var strDate = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + ' ' + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds() return currentdate }, // 两个日期对比 compareTime(oldTime, newTime) { return new Date(newTime).getTime() - new Date(oldTime).getTime() }, // 和当前时间对比 compareNowDate(yourDate) { return new Date(yourDate).getTime() - new Date().getTime() }, // 获取当前年度 getNowYear() { var date = new Date() var currentdate = date.getFullYear() + '' return currentdate }, // 获取上一年度 getAgoYear() { var date = new Date() var currentdate = date.getFullYear() - 1 + '' return currentdate }, // 获取n个月前当前日期 (YY-MM-DD) getBeforeMonthDay(monthNum) { var now_date = new Date() var seperator1 = '-' var now_month = now_date.getMonth() + 1 < 10 ? '0' + (now_date.getMonth() + 1) : now_date.getMonth() + 1 var now_strDate = now_date.getDate() < 10 ? '0' + now_date.getDate() : now_date.getDate() var currentdate = now_date.getFullYear() + seperator1 + now_month + seperator1 + now_strDate // 获取当前日期 const dateArr = currentdate.split('-') const year = dateArr[0] // 获取当前日期的年份 const month = dateArr[1] // 获取当前日期的月份 const day = dateArr[2] // 获取当前日期的日 // let days = new Date(year, month, 0) // days = days.getDate() // 获取当前日期中月的天数 let year2 = year let month2 = parseInt(month) - monthNum if (month2 <= 0) { year2 = parseInt(year2) - parseInt(month2 / 12 === 0 ? 1 : Math.abs(parseInt(month2 / 12)) + 1) month2 = 12 - (Math.abs(month2) % 12) } let day2 = day let days2 = new Date(year2, month2, 0) days2 = days2.getDate() if (day2 > days2) { day2 = days2 } if (month2 < 10) { month2 = '0' + month2 } const t2 = year2 + '-' + month2 + '-' + day2 return t2 } }