Date.prototype.setSeconds() changes the seconds and/or milliseconds of a date according to local time (MDN). It mutates the Date in place and returns the new timestamp.
Remember
date.setSeconds(seconds)
date.setSeconds(seconds, ms)
seconds: 0 … 59 (local)
ms: 0 … 999 (optional)
→ returns new timestamp (ms)
→ mutates date
setSeconds(42) // keep current ms
setSeconds(0, 0) // snap to :00.000
setSeconds(100) // overflow → +1 minute, :40
Syntax
Call date.setSeconds. Start with this line.
JavaScript
date.setSeconds(s[, ms])
Call
What it does
date.setSeconds(s[, ms])
Primary signature.
date.setSeconds(...)
Call with the arguments your case needs.
Built into JavaScript. Call setSeconds(...) on a Date instance — no import required.
Library declarations
JavaScript
date.setSeconds(s[, ms])
Parameters
Parameter
Description
secondsValue
Required. Local seconds (typically 0–59; overflow allowed)
msValue
Optional. Local milliseconds; keep current if omitted
Return Value
Return Value
Description
*
New epoch ms (number), not the Date
JavaScript Examples
Example 1 — Set the Seconds Only
MDN-style: change the seconds and keep the existing minutes.
Date.prototype.setSeconds() is part of the language from early ECMAScript and is Baseline Widely available (MDN).
✓ Baseline · Widely available
Date.prototype.setSeconds()
Supported in every modern browser and Node.js. No polyfill needed for ordinary web apps.
99%Modern browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
Date.setSeconds()Excellent
Bottom line: Safe everywhere. Focus on mutation, overflow into minutes, and DST when adjusting local seconds.
Frequently Asked Questions
It sets the seconds (0–59) of a Date in local time. An optional milliseconds argument can also set sub-second precision. The Date mutates in place and the method returns the new timestamp in milliseconds.
getSeconds() reads the local second. setSeconds(s) writes a new local second. They are the read/write pair for the second hand.
Yes. setSeconds(second, ms) updates both at once — useful for snapping to :00.000 at the start of a minute.
JavaScript normalizes overflow into the next minute. setSeconds(100) becomes +1 minute and 40 seconds (MDN).
No. It returns a number (epoch milliseconds). Call setters on the Date variable — do not chain on the return value.
setSeconds() changes the local clock second. setUTCSeconds() changes the UTC clock second. For fixed elapsed-time math across DST, prefer setUTCSeconds() or setTime().