JS把秒转为天时分

const dateCalculation = (second) => {
  if (second > 0) {
    let day = 0
    let hour = 0
    let minute = 0
    let data = {}
    minute = Math.floor(second / 60)
    if (parseInt(minute) > 60) {
      hour = parseInt(minute / 60)
      minute %= 60 //算出有多分钟
    }
    if (parseInt(hour) > 24) {
      day = parseInt(hour / 24)
      hour %= 24 //算出有多小时
    }
    data.day = day
    data.hour = hour
    data.minute = minute

    return `${data.day}:${data.hour}:${data.minute}`
  }
}

你可能感兴趣的:(JS把秒转为天时分)