const formatTime = seconds => {
const h = Math.floor(seconds / 3600);
const m = Math.floor((seconds % 3600) / 60);
const s = seconds % 60;
let result = '';
if (h > 0) {
result += `${h}:`;
}
result += `${m < 10 ? `0${m}` : m}:${s < 10 ? `0${s}` : s}`;
return result;
};
formateTime = time => {
const h = parseInt(time / 3600, 10);
const minute = parseInt((time / 60) % 60, 10);
const second = Math.ceil(time % 60);
const hours = h < 10 ? `0${h}` : h;
const formatSecond = second > 59 ? 59 : second;
let nowTime = '0秒';
if (h) {
nowTime = `${hours > 0 ? `${hours}时` : '00时'}${minute < 10 ? `0${minute}` : minute}分${
formatSecond < 10 ? `0${formatSecond}` : formatSecond
}秒`;
} else if (minute) {
nowTime = `${minute < 10 ? `0${minute}` : minute}分${
formatSecond < 10 ? `0${formatSecond}` : formatSecond
}秒`;
} else if (formatSecond) {
nowTime = `${formatSecond < 10 ? `0${formatSecond}` : formatSecond}秒`;
} else {
nowTime = '0秒';
}
return nowTime;
};
// 计算时长 转化成天 时 分 秒
const computeDuration = duration => {
const day = parseInt(duration / (24 * 60 * 60 * 1000), 10);
const dayRemainder = duration % (24 * 60 * 60 * 1000);
const hour = parseInt(dayRemainder / (60 * 60 * 1000), 10);
const hourRemainder = dayRemainder % (60 * 60 * 1000);
const minute = parseInt(hourRemainder / (60 * 1000), 10);
const minuteRemainder = hourRemainder % (60 * 1000);
const second = parseInt(minuteRemainder / 1000, 10);
return ((day && `${day}天`) || '') + ((hour && `${hour}小时`) || '') + ((minute && `${minute}分钟`) || '') + ((second && `${second}秒`) || '');
};