当仅仅需要在前端计算两个时间的差时使用,效果如下:
data初始化如下:
{ title: '#', dataIndex: '', key: 'rowIndex', width: 60, align: "center", customRender: function (t, r, index) { return parseInt(index) + 1; } },
{ title: '实际运输天数', lTitle: '实际运输天数/days', align: "center", dataIndex: '', customRender:function (t) { let a1 = Date.parse(t.tspAta); let a2 = Date.parse(t.tspAtd); if((a1-a2)>0){ let day = parseInt((a1-a2)/ (1000 * 60 * 60 * 24));//核心:时间戳相减,然后除以天数 let leave1 = (a1-a2) % (24 * 3600 * 1000); //计算天数后剩余的毫秒数 let hours = Math.floor(leave1 / (3600 * 1000)); //计算出小时数 let leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数 let minutes = Math.floor(leave2 / (60 * 1000)); //计算相差分钟数 let leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数 let seconds = Math.round(leave3 / 1000); return day+"天"+hours+"小时"+minutes+"分"+seconds+"秒"; } return ""; } }