首页 > 编程语言 >游戏陪玩系统源码,时间转换及时分秒差值计算

游戏陪玩系统源码,时间转换及时分秒差值计算

时间:2024-07-13 09:09:25浏览次数:18  
标签:sec floor 60 源码 差值 let 时分秒 Math

游戏陪玩系统源码,时间转换及时分秒差值计算

时间转换(秒数转时分秒)

function timeFormat (sec) {
    let minite = Math.floor((sec / 60 % 60)) < 10 ? '0' + Math.floor((sec / 60 % 60)) : Math.floor((sec / 60 % 60));
    let second = Math.floor((sec % 60)) < 10 ? '0' + Math.floor((sec % 60)) : Math.floor((sec % 60));
    if (sec < 3600) {
        return `${minite}:${second}`;
    } else {
        let hour = Math.floor(sec / 3600) < 10 ? '0' + Math.floor(sec / 3600) : Math.floor(sec / 3600);
        return `${hour}:${minite}:${second}`;
    }
}

 

计算时分秒差值

// 计算时分秒差值
function timeDiffer(beginTime, endTime) {
  let ret = {};
  let date = new Date();
  let sTime = Date.parse(dateFormat("YYYY/MM/DD", date) + " " + beginTime);
  if (beginTime >= endTime) {
    date.setDate(date.getDate() + 1);
  }
  let eTime = Date.parse(dateFormat("YYYY/MM/DD", date) + " " + endTime);
  let differ = eTime - sTime;
  let hour = Math.floor(differ / 1000 / 60 / 60);
  let minute = Math.floor(differ / 1000 / 60 - hour * 60);
  let second = Math.floor(differ / 1000 - hour * 60 * 60);
  ret = {
    differHour: hour,
    differMinute: minute,
    differSecond: second
  };
  return ret;
}
let { differHour, differMinute, differSecond } = timeDiffer(beginTime, endTime);

 

以上就是游戏陪玩系统源码,时间转换及时分秒差值计算, 更多内容欢迎关注之后的文章

 

标签:sec,floor,60,源码,差值,let,时分秒,Math
From: https://www.cnblogs.com/yunbaomengnan/p/18299670

相关文章