JavaScript 获取视频时长的时分秒


function getDuration(value,dateFormat){
  let hour = parseInt((value) / 3600);
  if (hour<10) {//时
    hour = "0" + hour;
  }
  var minute = parseInt((value % 3600) / 60);
  if (minute<10) {//分
    minute = "0" + minute;
  }
  var second = Math.ceil(value % 60);
  if (second<10) {//秒
    second = "0" + second;
  }
  switch (dateFormat) {
   case 'hh:mm':
    return hour + ":" + minute;
    break;
   case 'mm:ss':
    return minute + ":" + second;
    break;
   case 'hh':
    return hour;
    break;
   default:
    return hour + ":" + minute + ":" + second;
    break;
}

posted @ 2021-04-08 17:16  czfeng  阅读(489)  评论(0编辑  收藏  举报