File size: 497 Bytes
b59aa07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
 * Formats a time in milliseconds to the format "mm:ss"
 * @param ms The time in milliseconds
 * @returns The formatted time in the format "mm:ss"
 *
 * @example
 * formatMs(1000) // "00:01"
 * formatMs(1000 * 60) // "01:00"
 * formatMs(1000 * 60 * 2.5) // "02:30"
 */
export const formatMs = (ms: number) => {
  const minutes = Math.floor(ms / 1000 / 60);
  const seconds = Math.floor((ms / 1000) % 60);

  return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
};