/**
 * @Description: 时间毫秒数转成时间格式
 * @author guoxuhui
 * @date 2021-03-18
 * @time 19:36
 */
function encode(time: number) {
  const days = parseInt(String(time / (1000 * 60 * 60 * 24)));
  const hours = parseInt(String((time % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)));
  const minutes = parseInt(String((time % (1000 * 60 * 60)) / (1000 * 60)));
  const seconds = parseInt(String((time % (1000 * 60)) / 1000));
  if (days >= 1) {
    return days + " 天 " + hours + "小时 " + minutes + " 分钟 " + seconds + "秒";
  } else if (hours >= 1) {
    return hours + "小时 " + minutes + " 分钟 " + seconds + "秒";
  } else if (minutes >= 1) {
    return minutes + " 分钟 " + seconds + "秒";
  } else if (seconds >= 1) {
    return seconds + "秒";
  } else {
    return "0秒";
  }

  return "";
}

const TimeConvert = (code: number) => {
  return encode(code);
};

export default TimeConvert;
