var oldDate = ‘2017/02/07 00:00:00‘; setInterval(function () { var activeDate = new Date(); var diffDate = activeDate.getTime() - new Date(oldDate).getTime(); // ----------------------- var days = Math.floor(diffDate/(24*3600*1000)); var leave1 = diffDate%(24*3600*1000); var hours = Math.floor(leave1/(3600*1000)); var leave2 = leave1%(3600*1000); var minutes = Math.floor(leave2/(60*1000)); var leave3 = leave2%(60*1000); var seconds = Math.round(leave3/1000); console.log( "<i style=‘color:red;‘> " + days + " </i>天<i style=‘color:red;‘> " + hours + " </i>时<i style=‘color:red;‘> " + minutes + " </i>分<i style=‘color:red;‘> " + seconds + " </i>秒"); }, 1000);
计算某个时间到当前时间的差
原文地址:https://www.cnblogs.com/phpcurd/p/9127879.html
时间: 2024-11-05 16:07:21