var startDate = '2022-02-15 11:30:00' var endDate = '2022-02-15 09:00:00' var newDate = new Date(startDate); var oldDate = new Date(endDate); var diffDate = newDate - oldDate; //计算时间差毫秒 var days = parseInt(diffDate / (1000 * 60 * 60 * 24)); var hours = parseInt((diffDate % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = parseInt((diffDate % (1000 * 60 * 60)) / (1000 * 60)); var seconds = (diffDate % (1000 * 60)) / 1000;
console.log("毫秒: "+ diffDate); console.log("天: "+ days); console.log("时: "+ parseInt(days * 24 + hours)); console.log("分: "+ parseInt(days * 24 + hours * 60 + minutes)); console.log("秒:"+ parseInt(days * 24 + hours * 60 + minutes * 60 + seconds))
上面是“js计算2个时间的时间差(毫秒、天、时、分、秒)”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_1872.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!