有时,我们会把时长格式化成时分秒展示
具体实现
export function duration(timeStamp) {
let hour = parseInt((timeStamp % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
let minute = parseInt((timeStamp % (1000 * 60 * 60)) / (1000 * 60));
let second = parseInt((timeStamp % (1000 * 60)) / 1000);
hour = hour < 10 ? ('0' + hour) : hour;
minute = minute < 10 ? ('0' + minute) : minute;
second = second < 10 ? ('0' + second) : second;
return hour + ':' + minute + ':' + second;
}