diff --git a/src/utils/datetime.ts b/src/utils/datetime.ts new file mode 100644 index 0000000..2f2bb63 --- /dev/null +++ b/src/utils/datetime.ts @@ -0,0 +1,10 @@ +export const periodToString = (time?: number) => { + if (!time) return '00:00:00' + const hours = Math.floor(time / 3600) + const minutes = Math.floor(time / 60 - hours * 60) + const seconds = Math.floor(time - hours * 3600 - minutes * 60) + + const toFixed = (num: number) => `${num}`.padStart(2, '0') + + return `${toFixed(hours)}:${toFixed(minutes)}:${toFixed(seconds)}` +}