// 将秒转换为时分秒
formatDate = value => {
let secondTime = parseInt(value, 10); // 秒
let minuteTime = 0; // 分
let hourTime = 0; // 时
let result;
if (secondTime >= 60) {
// 如果秒数大于60,将秒数转换成整数
// 获取分钟,除以60取整数,得到整数分钟
minuteTime = parseInt(secondTime / 60, 10); // 获取秒数,秒数取佘,得到整数秒数
secondTime = parseInt(secondTime % 60, 10); // 如果分钟大于60,将分钟转换成小时
if (minuteTime >= 60) {
// 获取小时,获取分钟除以60,得到整数小时
hourTime = parseInt(minuteTime / 60, 10); // 获取小时后取佘的分,获取分钟除以60取佘的分
minuteTime = parseInt(minuteTime % 60, 10);
}
}
if (parseInt(secondTime, 10) < 10) {
result = `0${parseInt(secondTime, 10)}`;
} else {
result = parseInt(secondTime, 10);
}
if (minuteTime === 0) {
result = `00: ${result}`;
} else if (parseInt(minuteTime, 10) > 0 && parseInt(minuteTime, 10) < 10) {
result = `0${parseInt(minuteTime, 10)} : ${result}`;
} else if (
parseInt(minuteTime, 10) >= 10 &&
parseInt(minuteTime, 10) < 60
) {
result = `${parseInt(minuteTime, 10)} : ${result}`;
}
if (hourTime === 0) {
result = `00: ${result}`;
} else if (parseInt(hourTime, 10) > 0 && parseInt(hourTime, 10) < 10) {
result = `0${parseInt(hourTime, 10)} : ${result}`;
} else if (parseInt(hourTime, 10) >= 10 && parseInt(hourTime, 10) < 60) {
result = `${parseInt(hourTime, 10)} : ${result}`;
}
return result;
};
For example: the converted result of this.formatDate(71) is 00:01:11