function calculateDateDifference(date1, date2) { // 创建Date对象 var d1 = new Date(date1); var d2 = new Date(date2); // 转换为天数、小时、分钟和秒 var diff = Math.abs(d2.getTime() - d1.getTime()); var days = Math.floor(diff / (1000 * 60 * 60 * 24)); return days; } // 使用示例: var dateString1 = "2024-01-02 00:00:01"; var dateString2 = "2024-01-03 00:00:00"; var difference = calculateDateDifference(dateString1, dateString2); console.log(difference); // 输出:44天 0小时 0分钟 0秒