xref: /MusicFree/src/utils/timeformat.ts (revision 5d19d26c98d1c233995663070b95e5f28b5b9e1c)
1export default function (time: number) {
2    if (time < 60) {
3        return `00:${time.toFixed(0).padStart(2, '0')}`;
4    }
5    const sec = Math.floor(time % 60);
6    time = Math.floor(time / 60);
7    const min = time % 60;
8    time = Math.floor(time / 60);
9    const formatted = `${min.toString().padStart(2, '0')}:${sec
10        .toFixed(0)
11        .padStart(2, '0')}`;
12    if (time === 0) {
13        return formatted;
14    }
15
16    return `${time}:${formatted}`;
17}
18