Function msToTime

  • Returns a time object (or a converted equivalent if a format is provided) converted from milliseconds.

    Parameters

    • milliseconds: number

      The milliseconds to convert.

    • format: TimeFormats

      The format to convert to. Accepts 's' for seconds, 'm' for minutes, 'h' for hours, 'd' for days.

    Returns number

    TimeObject or the converted equivalent if a format is provided.

    See

    Reference

    Example

    // { d: 2, h: 3, m: 4, s: 5 }
    msToTime(1000 * 60 * 60 * 24 * 2 + 1000 * 60 * 60 * 3 + 1000 * 60 * 4 + 1000 * 5 + 6)

    Example

    // 2
    msToTime(1000 * 60 * 60 * 24 * 2 + 1000 * 60 * 60 * 3 + 1000 * 60 * 4 + 1000 * 5 + 6, 'd')

    Example

    // 51
    msToTime(1000 * 60 * 60 * 24 * 2 + 1000 * 60 * 60 * 3 + 1000 * 60 * 4 + 1000 * 5 + 6, 'h')

    Example

    // 3064
    msToTime(1000 * 60 * 60 * 24 * 2 + 1000 * 60 * 60 * 3 + 1000 * 60 * 4 + 1000 * 5 + 6, 'm')

    Example

    // 183845
    msToTime(1000 * 60 * 60 * 24 * 2 + 1000 * 60 * 60 * 3 + 1000 * 60 * 4 + 1000 * 5 + 6, 's')
  • Parameters

    • milliseconds: number

    Returns TimeObject