formatTime
Call Signature
formatTime(
ms
,format
?,returnFormat
?):TimerObject
Defined in: plugins/TimerPlugin.ts:162
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
ms
number
Time duration in milliseconds to format
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?
"object"
Determines the return type
- ‘string’ (default): Returns formatted time string
- ‘object’: Returns object with h, m, s, ms properties
Returns
Formatted time string or object containing time components
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
formatTime(
ms
,format
?,returnFormat
?):string
Defined in: plugins/TimerPlugin.ts:163
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
ms
number
Time duration in milliseconds to format
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?
"string"
Determines the return type
- ‘string’ (default): Returns formatted time string
- ‘object’: Returns object with h, m, s, ms properties
Returns
string
Formatted time string or object containing time components
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');};