Ms
The main function interface that formats and parses durations.Format overloads
When you pass a number, the function formats milliseconds to a human-readable string:Parse overload
When you pass a string, the function parses a duration string into milliseconds:CreateMsOptions
Options for creating a custom ms instance withcreateMs().
The language to use for formatting and parsing. Can be a language key (e.g.,
'en', 'de', 'ru') or a custom language definition object.Default formatting options to use when formatting milliseconds. See FormatOptions below.
Example
FormatOptions
Options for customizing duration formatting.Extends a preset with the given options. See Format presets.
Hide unit names from the output. Used as part of the
colonNotation preset.Use abbreviations for unit names (e.g., “m” instead of “minute”).
Include units with the value 0 in the output. Used as part of the
colonNotation preset.Include milliseconds in the output. Shorthand for adding
'millisecond' to the includedUnits option.Include sub-millisecond units (microseconds and nanoseconds) in the output. Enabling this option automatically enables
includeMs. Shorthand for adding 'microsecond' and 'nanosecond' to the includedUnits option.Which units should be included in the output. Valid units:
'year', 'day', 'hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond'.The maximum number of units to include in the output. If set to
-1, all units will be included.The separator to use between units.
The minimum number of digits for a unit. Will pad with leading zeroes. Used as part of the
colonNotation preset.Example
FormatOptionsPreset
Pre-configured formatting presets.Uses abbreviations and limits output to 2 units.Example:
1m 30sIncludes milliseconds, microseconds, and nanoseconds.Example:
10 seconds 100 milliseconds 100 microseconds 100 nanosecondsUses colon-separated format without unit names, similar to digital clocks.Example:
01:30:45Example
ParseUnit
Valid unit types that can be used in formatting.includedUnits option of FormatOptions.
LanguageDefinition
Interface for defining custom language support.The decimal separator the language uses. For example,
'.' for English, ',' for German.The string or factory function to use for the “and” conjunction. For example,
'and' for English, 'und' for German.Definitions for each time unit in the language. See LanguageUnitDefinition.
Example
LanguageUnitDefinition
Definition for a single time unit in a language.The string or factory function to use for the unit name. For example,
'hour' for English, or a function that returns 'hour' or 'hours' based on count.The string or factory function to use for the unit abbreviation. For example,
'h' for English. Required if you want to use useAbbreviations option.A list of lowercase strings to use for matching units when parsing duration strings. For example,
['h', 'hr', 'hour', 'hours'] for English hours.