setSeconds() writes the second (0–59) on a Date in local time, with an optional milliseconds argument. This guide covers syntax, minute-boundary snaps, overflow, and comparisons with UTC setters.
01
Syntax
setSeconds(s)
02
0–59
Seconds
03
+ ms
2nd arg
04
Mutates
In place
05
Overflow
Rolls minutes
06
Returns
Epoch ms
Fundamentals
Introduction
Timestamps from logs, APIs, and cron jobs often need their second component adjusted. After reading seconds with getSeconds(), setSeconds() writes them back in local time.
Like other setters, it mutates the original object and returns epoch milliseconds—not the Date for chaining.
Concept
Understanding the setSeconds() Method
Date.prototype.setSeconds(second [, millisecond]) accepts a local second and an optional millisecond (0–999). When you pass only the second, minutes and hours stay the same unless overflow normalization rolls the clock forward.
Values outside normal ranges normalize— setSeconds(90) becomes 1 minute and 30 seconds later. For UTC second writes, use setUTCSeconds().
💡
Beginner Tip
To snap to the start of a minute: date.setSeconds(0, 0). For exact :45.500 marks: date.setSeconds(45, 500).
90 seconds = 1 minute + 30 seconds. The engine normalizes instead of clamping to 59.
Applications
🚀 Common Use Cases
Log alignment — setSeconds(0, 0) for minute buckets.
API timestamps — apply second/ms from parsed ISO strings.
Test fixtures — pin exact second/ms in unit tests.
Cron alignment — snap events to :00 at minute boundaries.
Form time pickers — apply user-selected seconds to a Date.
Clone + mutate — keep originals when tweaking sub-minute fields.
🧠 How setSeconds() Updates the Clock
1
Read local time
Engine loads hour, minute, second, and ms fields.
Local
2
Apply new second
Second and optional ms replace old sub-minute values.
setSeconds
3
Normalize overflow
Out-of-range values roll into adjacent minutes or hours.
Normalize
4
⏱
Mutate & return ms
Date updates in place; epoch milliseconds are returned.
Important
📝 Notes
setSeconds() uses local time seconds 0–59 (overflow normalizes).
For elapsed duration, use end.getTime() - start.getTime()—not clock getters.
Mutates the original Date—clone with new Date(date) when needed.
Returns epoch ms, not the Date—no fluent chaining on the return value.
Optional millisecond defaults to 0 when omitted in two-arg calls.
Use setUTCSeconds when rules follow UTC, not local wall clock.
Compatibility
Browser & Runtime Support
Date.prototype.setSeconds() has been available since ES1. It works in every browser and Node.js.
✓ Baseline · ES1
Date.prototype.setSeconds()
Supported in Chrome, Firefox, Safari, Edge, Internet Explorer, and all Node.js versions. No polyfill required.
99%Universal API
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. Remember mutation, overflow, and getTime() for duration.
Wrap Up
Conclusion
setSeconds() writes the local second (and optionally milliseconds) on a JavaScript Date. Use it for minute snaps and precise sub-minute timestamps; clone first when preserving the original instant.
Next, learn setTime() to set the full epoch timestamp at once, or review getSeconds() for reading the second component.
Use setSeconds(45, 500) for exact sub-minute times
Clone before mutating shared Date instances
Pair with getSeconds() to verify results
Use getTime() for elapsed measurements
❌ Don’t
Chain setters on the numeric return value
Assume values clamp at 59 (overflow rolls minutes)
Use setSeconds(n) to mean “n seconds elapsed”
Mix local setters with UTC getters in one label
Rely on manual 0–59 validation when overflow is acceptable
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Date.setSeconds()
Your foundation for local second writes in JavaScript.
5
Core concepts
📝01
Syntax
setSeconds(s)
API
🔢02
0–59
Seconds.
Range
📈03
2 args
s, ms.
Overload
⚠04
Overflow
Rolls minutes.
Normalize
🔄05
Clone
Keep original.
Pattern
❓ Frequently Asked Questions
It sets the seconds (0–59) of a Date object in local time. An optional milliseconds argument can also set sub-second precision. The Date mutates in place and returns updated epoch milliseconds.
getSeconds() reads the current local second. setSeconds(s) writes a new second. They are the read/write pair for the second hand of the local clock.
Yes. setSeconds(second, millisecond) updates both fields at once—useful for snapping to :00.000 at the start of a minute.
JavaScript normalizes overflow into the next minute. setSeconds(90) on 12:30:45 becomes 12:31:30 (90 seconds = 1 minute + 30 seconds).
No. It returns a number (epoch milliseconds). Call each setter on the same Date variable—do not chain on the return value.
setSeconds() changes the local clock second. setUTCSeconds() changes the UTC clock second. Use the one that matches your timezone rules.
Did you know?
setSeconds(15) sets the clock’s second hand to 15—it does not mean “15 seconds from now.” For elapsed time, subtract Date.now() - start or use getTime().