The base date as a Date object or timestamp (number)
The milliseconds to set (typically 0-999, fractions are truncated)
A new Date object with the milliseconds set, or Invalid Date if any input is invalid
// Set milliseconds to a typical value
const result = setMilliseconds(new Date(2025, 0, 15, 12, 30, 45, 123), 500);
// Returns: 2025-01-15 12:30:45.500
// Set milliseconds to minimum value
const result2 = setMilliseconds(new Date(2025, 0, 15, 12, 30, 45, 123), 0);
// Returns: 2025-01-15 12:30:45.000
// Rollover to next second with value >= 1000
const result3 = setMilliseconds(new Date(2025, 0, 15, 12, 30, 45, 500), 1000);
// Returns: 2025-01-15 12:30:46.000
// Fractional milliseconds are truncated
const result4 = setMilliseconds(new Date(2025, 0, 15, 12, 30, 45, 123), 500.9);
// Returns: 2025-01-15 12:30:45.500
// Invalid date returns Invalid Date
const result5 = setMilliseconds(new Date("invalid"), 500);
// Returns: Invalid Date
Set the milliseconds of the given date.
This function validates arguments before processing and returns a new Date instance with the specified milliseconds set. Fractional milliseconds are truncated toward zero.