var date1 = new Date(); //实例化现在的时间 var date2 = new Date('2020-12-30 20:36-58'); var dateDis = (date2 - date1) / 1000; //相差的总秒数 var days = parseInt(dateDis / 60 / 60 / 24); //相差总天数 days = days > 10 ? days : "0" + days; var hours = parseInt(dateDis / 60 / 60 % 24); //相差总小时数 hours = hours > 10 ? hours : "0" + hours; var minutes = parseInt(dateDis / 60 % 60); //相差总分钟数 minutes = minutes > 10 ? minutes : "0" + minutes; var seconds = parseInt(dateDis % 60); //相差的总秒数 seconds = seconds > 10 ? seconds : "0" + seconds; console.log("剩余时间为:" + days + "天" + hours + "时" + minutes + "分钟" + seconds + "秒");
标签:10,01,seconds,09,hours,days,60,var From: https://www.cnblogs.com/zhaofen/p/17115768.html