Skip to main content Link Search Menu Expand Document Toggle dark mode Copy Code (external link)

addMilliseconds() : Add Milliseconds to Date

Add milliseconds to a datetime. Use negative values to subtract milliseconds.


On this page

Signature

addMilliseconds(date, milliseconds)

Parameters

Parameter Type Required Description
date DateTime Yes The datetime to modify
milliseconds Number Yes Number of milliseconds to add (can be negative)

Returns

Type: DateTime

A new DateTime with the specified milliseconds added.


Examples

Add Milliseconds

<p>Precise time: {{format(addMilliseconds(model.time, 500), 'h:mm:ss.fff tt')}}</p>

Data:

doc.Params["model"] = new {
    time = new DateTime(2024, 3, 15, 14, 30, 0, 0)
};

Output:

<p>Precise time: 2:30:00.500 PM</p>

Performance Timing

<p>Duration: {{model.elapsedMs}} ms</p>
<p>Ended: {{format(addMilliseconds(model.started, model.elapsedMs), 'h:mm:ss.fff')}}</p>

Data:

doc.Params["model"] = new {
    started = new DateTime(2024, 3, 15, 10, 0, 0, 0),
    elapsedMs = 1250
};

Output:

<p>Duration: 1250 ms</p>
<p>Ended: 10:00:01.250</p>

High-Precision Timestamps

<p>Timestamp: {{format(addMilliseconds(model.base, model.offset), 'yyyy-MM-dd HH:mm:ss.fff')}}</p>

Notes

  • Input datetime is not modified (returns new datetime)
  • Can add positive or negative milliseconds
  • Automatically handles second, minute, hour, and day boundaries
  • Most precise time addition function
  • Use addSeconds() for second-level precision

See Also