The base date as a Date object or timestamp (number)
The seconds to set (0-59 for normal range, other values will roll over)
A new Date object with the seconds set, or Invalid Date if any input is invalid
// Set seconds to 30
const result = setSeconds(new Date(2025, 0, 15, 12, 30, 45), 30);
// Returns: 2025-01-15 12:30:30
// Set seconds to 0 (start of minute)
const result2 = setSeconds(new Date(2025, 0, 15, 12, 30, 45), 0);
// Returns: 2025-01-15 12:30:00
// Seconds rollover to next minute
const result3 = setSeconds(new Date(2025, 0, 15, 12, 30, 45), 60);
// Returns: 2025-01-15 12:31:00
// Fractional seconds are truncated
const result4 = setSeconds(new Date(2025, 0, 15, 12, 30, 45), 30.9);
// Returns: 2025-01-15 12:30:30
// Invalid date returns Invalid Date
const result5 = setSeconds(new Date("invalid"), 30);
// Returns: Invalid Date
Set the seconds of the given date.
This function validates arguments before processing and returns a new Date instance with the specified seconds set. Fractional seconds are truncated toward zero.