@unikue/ts-lang-utils
    Preparing search index...

    Function formatSeconds

    Utilities for duration

    David Hsing

    • Formats the given seconds into a human-readable time string (HH:MM:SS or MM:SS)

      Parameters

      • Optionalseconds: number | null

        the number of seconds to format

      • forceHour: boolean = false

        whether to always include the hour part even when it is zero (defaults to false)

      Returns string | undefined

      the formatted time string, e.g. "03:45" or "01:02:03", or undefined if seconds is absent

      David Hsing

      formatSeconds(36);               // "00:36"
      formatSeconds(125); // "02:05"
      formatSeconds(3661); // "01:01:01"
      formatSeconds(36, true); // "00:00:36"
      formatSeconds(125, true); // "00:02:05"
      formatSeconds(-1); // "00:00"
      formatSeconds(Infinity); // "00:00"
      formatSeconds(); // undefined
      formatSeconds(undefined); // undefined
      formatSeconds(null); // undefined