export default { /*** 根据时间返回时间字符串 Input => date Output => 2022-11-12**/ getDateStrByTime(date) { date = new Date(date) let year = date.getFullYear(); let month = date.getMonth() + 1 >= 10 ? (date.getMonth() + 1) : ('0' + (date.getMonth() + 1)); let day = date.getDate() >= 10 ? date.getDate() : ('0' + date.getDate()); return `${year}/${month}/${day}`; }, /***根据时间增减天数返回时间字符串 Input => date,count(正负增减) Output => 2022-11-12**/ getStrByTimeIncreaseDay(date, count) { date = new Date(date) date = new Date(date.setDate(date.getDate() + count)); return this.getDateStrByTime(date) }, /***根据开始时间、结束时间获取该时间段日期字符串数组 Input => date1,date2 Output => ["2022-04-19",2022-04-20"] **/ getDayAll(starDay, endDay) { var arr = []; var dates = []; // 设置两个日期UTC时间 var db = new Date(starDay); var de = new Date(endDay); // 获取两个日期GTM时间 var s = db.getTime() - 24 * 60 * 60 * 1000; var d = de.getTime() - 24 * 60 * 60 * 1000; // 获取到两个日期之间的每一天的毫秒数 for (var i = s; i <= d;) { i = i + 24 * 60 * 60 * 1000; arr.push(parseInt(i)) } // 获取每一天的时间 YY-MM-DD for (var j in arr) { var time = new Date(arr[j]); var year = time.getFullYear(time); var mouth = (time.getMonth() + 1) >= 10 ? (time.getMonth() + 1) : ('0' + (time.getMonth() + 1)); var day = time.getDate() >= 10 ? time.getDate() : ('0' + time.getDate()); var YYMMDD = year + '/' + mouth + '/' + day; dates.push(YYMMDD) } return dates }, changeDateTime(date, format) { date = new Date(date) let year = date.getFullYear(); let month = date.getMonth() + 1 >= 10 ? (date.getMonth() + 1) : ('0' + (date.getMonth() + 1)); let day = date.getDate() >= 10 ? date.getDate() : ('0' + date.getDate()); let str = year + "/" + month + "/" + day + ' ' + format console.log(str) return new Date(str); }, isSameDay(date1, date2) { date1 = new Date(date1) date2 = new Date(date2) if (date1.getFullYear() == date2.getFullYear() && date1.getMonth() == date2.getMonth() && date1.getDate() == date2.getDate()) { return true; } return false; } }