三个参数,第一个参数为要对比的时间,后面参数为要对比的天数
export const compareDateWithCurrent = (inputDateStr, date1, date2) => {
const inputDate = new Date(inputDateStr)
const currentDate = new Date()
// 获取时间差的毫秒数
const timeDifference = inputDate - currentDate
// 获取时间差的天数
const daysDifference = Math.floor(timeDifference / (1000 * 60 * 60 * 24))
console.log(daysDifference)
if (daysDifference > date1) {
return green //绿色
} else if (daysDifference >= date2 && daysDifference <= date1) {
return yellow //黄色
} else {
return red
}
}