@darthcav/ts-utils
    Preparing search index...

    Function millisecondsToString

    • Converts a duration in milliseconds to a human-readable string such as "1d 4h 32m 10s 250ms".

      Milliseconds are shown as their own integer component; fractional inputs are rounded to the nearest millisecond. Any zero-valued components are omitted from the formatted output, so a zero-millisecond input produces an empty string. Negative durations are formatted from their magnitude and prefixed with "-" (e.g. -90_000"-1m 30s").

      Parameters

      • ms: number

        Duration in milliseconds. Must be a finite number.

      • locale: string = "en"

        BCP 47 locale tag passed to Intl.DurationFormat. Defaults to "en".

      Returns string

      A formatted duration string.

      If ms is not finite (NaN, Infinity, -Infinity) or locale is not a valid BCP 47 language tag.

      millisecondsToString(3_661_000)       // "1h 1m 1s"
      millisecondsToString(90_000) // "1m 30s"
      millisecondsToString(5_250) // "5s 250ms"
      millisecondsToString(499) // "499ms"
      millisecondsToString(-90_000) // "-1m 30s"
      millisecondsToString(90_061_000, "es") // "1d 1h 1min 1s"