function calculateDaysDifference(targetDateString) { const currentDate = new Date(); const targetDate = new Date(targetDateString); // 计算毫秒差异 const timeDifference = targetDate - currentDate; // 计算天数差异,如果结果为负数,则设置为0 const daysDifference = Math.max(Math.floor(timeDifference / (1000 * 60 * 60 * 24)), 0); // 计算小时差异,如果结果为负数,则设置为0 const hoursDifference = Math.max(Math.floor((timeDifference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)), 0); // 计算分钟差异,如果结果为负数,则设置为0 const minutesDifference = Math.max(Math.floor((timeDifference % (1000 * 60 * 60)) / (1000 * 60)), 0); return { days: daysDifference, hours: hoursDifference, minutes: minutesDifference }; }