subtracks/src/util.ts
2021-07-05 10:27:30 +09:00

12 lines
310 B
TypeScript

export function formatDuration(seconds: number): string {
const s = seconds % 60
const m = Math.floor(seconds / 60) % 60
const h = Math.floor(seconds / 60 / 60)
let time = `${m.toString().padStart(1, '0')}:${s.toString().padStart(2, '0')}`
if (h > 0) {
time = `${h}:${time}`
}
return time
}