Skip to content

formatTime

formatTime(ms, format?, returnFormat?): TimerObject

Defined in: plugins/TimerPlugin.ts:176

Formats a time duration in milliseconds into a human-readable string or object. Supports multiple time formats and return types for flexible time representation.

number

Time duration in milliseconds to format

TimeFormat

Output format for string representation

  • ‘mm:ss’ (default): Minutes and seconds (e.g., “02:30”)
  • ‘hh:mm:ss’: Hours, minutes, and seconds (e.g., “01:30:45”)
  • ‘ms’: Total seconds with milliseconds (e.g., “90.50”)

"object"

Determines the return type

  • ‘string’ (default): Returns formatted time string
  • ‘object’: Returns object with h, m, s, ms properties

TimerObject

Formatted time string or object containing time components

// Format as mm:ss string (default)
formatTime(150000) // "02:30"
// Format as hh:mm:ss string
formatTime(5430000, 'hh:mm:ss') // "01:30:30"
// Format as seconds with milliseconds
formatTime(90500, 'ms') // "90.50"
// Get time components as object
formatTime(5430000, 'hh:mm:ss', 'object')
// Returns: { h: 1, m: 30, s: 30, ms: 0 }
// Use in a game timer display
timer.onTick = (remaining) => {
display.text = formatTime(remaining, 'mm:ss');
};

formatTime(ms, format?, returnFormat?): string

Defined in: plugins/TimerPlugin.ts:177

Formats a time duration in milliseconds into a human-readable string or object. Supports multiple time formats and return types for flexible time representation.

number

Time duration in milliseconds to format

TimeFormat

Output format for string representation

  • ‘mm:ss’ (default): Minutes and seconds (e.g., “02:30”)
  • ‘hh:mm:ss’: Hours, minutes, and seconds (e.g., “01:30:45”)
  • ‘ms’: Total seconds with milliseconds (e.g., “90.50”)

"string"

Determines the return type

  • ‘string’ (default): Returns formatted time string
  • ‘object’: Returns object with h, m, s, ms properties

string

Formatted time string or object containing time components

// Format as mm:ss string (default)
formatTime(150000) // "02:30"
// Format as hh:mm:ss string
formatTime(5430000, 'hh:mm:ss') // "01:30:30"
// Format as seconds with milliseconds
formatTime(90500, 'ms') // "90.50"
// Get time components as object
formatTime(5430000, 'hh:mm:ss', 'object')
// Returns: { h: 1, m: 30, s: 30, ms: 0 }
// Use in a game timer display
timer.onTick = (remaining) => {
display.text = formatTime(remaining, 'mm:ss');
};