web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

js计算器时间差(天、时、分秒)

463 ℃
     
function twoTimeInterval(startTime, endTime) {
 
  // 开始时间
  let d1 = startTime.replace(/\-/g, "/");
  let date1 = new Date(d1);
 
  // 结束时间
  let d2 = endTime.replace(/\-/g, "/");
  let date2 = new Date(d2);
 
  // 时间相差秒数
  let dateDiff = date2.getTime() - date1.getTime();
 
  // 计算出相差天数
  let days = Math.floor(dateDiff / (24 * 3600 * 1000));
 
  // 计算出小时数
  let residue1 = dateDiff % (24 * 3600 * 1000); // 计算天数后剩余的毫秒数
  let hours = Math.floor(residue1 / (3600 * 1000));
 
  // 计算相差分钟数
  let residue2 = residue1 % (3600 * 1000); // 计算小时数后剩余的毫秒数
  let minutes = Math.floor(residue2 / (60 * 1000));
 
  // 计算相差秒数
  let residue3 = residue2 % (60 * 1000); // 计算分钟数后剩余的毫秒数
  let seconds = Math.round(residue3 / 1000);
 
  let returnVal =
    ((days == 0) ? "" : days+"天") +
    ((hours == 0) ? "" : days+"时") +
    ((minutes == 0) ? "" : minutes+"分") +
    ((seconds == 0) ? "" : seconds+"秒");
 
  return returnVal;
 
}

js获取2个时间差之间所有月份

js计算2个时间的时间差(毫秒、天、时、分、秒)

2两个时间计算时间差(到天,时,分,秒)

标签: 时间差

上面是“js计算器时间差(天、时、分秒)”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_1836.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > js
本文共计696个字,预计阅读时长5分钟
生活小工具,收录了80多款小工具
上一篇: 推荐一个可以查询老黄历的网站,可以根据五行取名!
下一篇: 详细介绍HTTP状态码不同之处的原因(什么原因导致的)
x 打工人ai神器