传入日期减去当前日期,得到剩余天数:
const calculateDate = (days) => {
const myDate = new Date();
const myToday = `${myDate.getFullYear()}-${myDate.getMonth() + 1}-${myDate.getDate()}`;
const date1 = new Date(days);
// console.log('myToday', myToday);
const today = new Date(myToday);
// const date2=new Date(yyyy-MM-dd);
const date = (date1.getTime() - today.getTime()) / (1000 * 60 * 60 * 24); // 不考虑闰年否
return date.toFixed(0);
};