1
0
Fork 0
mirror of https://github.com/CorentinTh/it-tools.git synced 2025-07-30 18:49:37 +02:00
it-tools/src/tools/chronometer/chronometer.service.ts
2022-08-04 09:06:42 +02:00

11 lines
459 B
TypeScript

export function formatMs(msTotal: number) {
const ms = msTotal % 1000;
const secs = ((msTotal - ms) / 1000) % 60;
const mins = (((msTotal - ms) / 1000 - secs) / 60) % 60;
const hrs = (((msTotal - ms) / 1000 - secs) / 60 - mins) / 60;
const hrsString = hrs > 0 ? `${hrs.toString().padStart(2, '0')}:` : '';
return `${hrsString}${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}.${ms
.toString()
.padStart(3, '0')}`;
}