1. 将秒值转换成时分秒。
function secondsToTime(seconds) {
let hours, minutes;
if (seconds >= 3600) {
hours = Math.floor(seconds / 3600);
}
if ((seconds % 3600) > 0) {
minutes = Math.floor((seconds % 3600) / 60);
}
const remainingSeconds = seconds % 60;
let res = '';
if (hours > 0) {
res = res + hours + '小时';
}
if (minutes > 0) {
res = res + minutes + '分钟';
}
if (remainingSeconds > 0) {
res = res + remainingSeconds + '秒';
}
return res;
}
2.持续更新