getTime(beginTime, endTime) { var dateDiff = endTime.getTime() - beginTime.getTime(); //时间差的毫秒数 var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数 var leave1 = dateDiff % (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( " 相差 " + dayDiff + "天 " + hours + "小时 " + minutes + " 分钟" + seconds + " 秒" ); return "相差 " + dayDiff + "天 " + hours + "小时 " + minutes + " 分钟"; },
开始时间和结束时间时间差
<div class="des-status-df">开始</div> <div class="block"> <el-date-picker v-model="startTime" type="datetime" placeholder="选择日期时间" @change="jsTime" > </el-date-picker> </div> <div class="des-status-df">结束</div> <div class="block"> <el-date-picker v-model="endTime" type="datetime" placeholder="选择日期时间" @change="jsTime" > </el-date-picker> </div> <div class="des-time-box"> <span class="des-time">共计</span> <span class="des-time-red">{{duration}}</span> <span class="des-time">小时</span> </div>
data
duration: "", startTime: "", endTime: "",