码迷,mamicode.com
首页 > 其他好文 > 详细

前端计算两个时间差以时分秒的格式展示

时间:2021-04-24 11:48:09      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:展示   floor   return   前端   math   stay   mat   时分秒   time   

let staytimeGap = new Date(closedtime).getTime() - new Date(createtime).getTime();
let stayHour = Math.floor(staytimeGap / (3600 * 1000));
let leave1 = staytimeGap % (3600 * 1000);
let stayMin = Math.floor(leave1 / (60 * 1000));
let leave2 = leave1 % (60 * 1000);
let staySec = Math.floor(leave2 / 1000);
stayHour = stayHour < 10 ? "0" + stayHour : stayHour;
stayMin = stayMin < 10 ? "0" + stayMin : stayMin;
staySec = staySec < 10 ? "0" + staySec : staySec;
return stayHour + ":" + stayMin + ":" + staySec;

前端计算两个时间差以时分秒的格式展示

标签:展示   floor   return   前端   math   stay   mat   时分秒   time   

原文地址:https://www.cnblogs.com/xiao1993/p/14693055.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!