formatTime
Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”number
Time duration in milliseconds to format
format?
Section titled “format?”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”)
returnFormat?
Section titled “returnFormat?”"object"
Determines the return type
- ‘string’ (default): Returns formatted time string
- ‘object’: Returns object with h, m, s, ms properties
Returns
Section titled “Returns”Formatted time string or object containing time components
Example
Section titled “Example”// Format as mm:ss string (default)formatTime(150000) // "02:30"
// Format as hh:mm:ss stringformatTime(5430000, 'hh:mm:ss') // "01:30:30"
// Format as seconds with millisecondsformatTime(90500, 'ms') // "90.50"
// Get time components as objectformatTime(5430000, 'hh:mm:ss', 'object')// Returns: { h: 1, m: 30, s: 30, ms: 0 }
// Use in a game timer displaytimer.onTick = (remaining) => { display.text = formatTime(remaining, 'mm:ss');};
Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”number
Time duration in milliseconds to format
format?
Section titled “format?”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”)
returnFormat?
Section titled “returnFormat?”"string"
Determines the return type
- ‘string’ (default): Returns formatted time string
- ‘object’: Returns object with h, m, s, ms properties
Returns
Section titled “Returns”string
Formatted time string or object containing time components
Example
Section titled “Example”// Format as mm:ss string (default)formatTime(150000) // "02:30"
// Format as hh:mm:ss stringformatTime(5430000, 'hh:mm:ss') // "01:30:30"
// Format as seconds with millisecondsformatTime(90500, 'ms') // "90.50"
// Get time components as objectformatTime(5430000, 'hh:mm:ss', 'object')// Returns: { h: 1, m: 30, s: 30, ms: 0 }
// Use in a game timer displaytimer.onTick = (remaining) => { display.text = formatTime(remaining, 'mm:ss');};