The base date as a Date object or timestamp (number)
The number of milliseconds to add (can be negative to subtract)
A new Date object with the milliseconds added, or Invalid Date if any input is invalid
// Add positive milliseconds
const result = addMilliseconds(new Date(2020, 0, 1, 12, 0, 0, 0), 500);
// Returns: 2020-01-01T12:00:00.500
// Subtract milliseconds (negative amount)
const result = addMilliseconds(new Date(2020, 0, 1, 12, 0, 0, 500), -300);
// Returns: 2020-01-01T12:00:00.200
// Fractional amounts are truncated
const result = addMilliseconds(new Date(2020, 0, 1, 12, 0, 0, 0), 1.9);
// Returns: 2020-01-01T12:00:00.001 (1.9 truncated to 1)
// Crossing second boundary
const result = addMilliseconds(new Date(2020, 0, 1, 12, 0, 0, 999), 1);
// Returns: 2020-01-01T12:00:01.000
// Invalid inputs return Invalid Date
const result = addMilliseconds(new Date("invalid"), 500);
// Returns: Invalid Date
Add the specified number of milliseconds to the given date.
This function validates arguments before processing and returns a new Date instance with the specified number of milliseconds added. Fractional milliseconds are truncated toward zero.