Milliseconds to short time

    0

    0

    timeconvert

    Convert milliseconds to short time.

    Filename pattern: *.js

    const msToShort = (milliseconds) => {
      const seconds = Math.floor(milliseconds / 1000);
      const minutes = Math.floor(seconds / 60);
      const hours = Math.floor(minutes / 60);
    
      const units = [
        { unit: 'h', value: hours },
        { unit: 'm', value: minutes % 60 },
        { unit: 's', value: seconds % 60 },
        { unit: 'ms', value: milliseconds % 1000 },
      ];
    
      return units
        .filter((unit) => unit.value > 0)
        .map(({ unit, value }) => `${value}${unit}`)
        .join(' ');
    };
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.