Skip to main content Link Search Menu Expand Document (external link)

addMilliseconds() : Add Milliseconds to Date


On this page

Summary

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

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: </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:  ms</p>
<p>Ended: </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: </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