utils.ts 590 B

123456789101112131415
  1. export const formatTime = (time: number) => {
  2. if (isNaN(time)) {
  3. return '00:00';
  4. }
  5. const hours = Math.floor(time / 3600);
  6. if (hours > 0) {
  7. const minutes = Math.floor((time - hours * 3600) / 60);
  8. const seconds = Math.floor(time % 60);
  9. return `${hours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
  10. } else {
  11. const minutes = Math.floor(time / 60);
  12. const seconds = Math.floor(time % 60);
  13. return `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
  14. }
  15. };