计算时间差的方法

export function timestampDiff(endTimestamp,startTimestamp) {
  const  mss = endTimestamp - startTimestamp;
  const days = parseInt(mss / (1000 * 60 * 60 * 24) ,10);
  const hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60) ,10) + days * 24;
  const minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60), 10);
  const seconds = parseInt((mss % (1000 * 60)) / 1000 ,10);
  return `${hours.toString().length > 1 ?  hours : `0${hours}`}:${minutes.toString().length > 1 ?  minutes : `0${minutes}`}:${seconds.toString().length > 1 ?  seconds : `0${seconds}`}`; 
}

计算时间差的方法 单位小时

猜你喜欢

转载自www.cnblogs.com/l8l8/p/10530589.html