setHours() writes the hour (0–23) on a Date object in local time, with optional minutes, seconds, and milliseconds. This guide covers syntax, scheduling patterns, overflow, and comparisons with UTC setters.
01
Syntax
setHours(h)
02
24h
0 – 23
03
Overload
h, m, s, ms
04
Mutates
In place
05
+ hours
getHours + n
06
Returns
Epoch ms
Fundamentals
Introduction
Reminders, meeting times, and “open at 9 AM” rules need to change the clock on a Date. After reading the hour with getHours(), setHours() writes it back in local time.
Like other setters, it mutates the original object and returns epoch milliseconds—not the Date for chaining.
Concept
Understanding the setHours() Method
Date.prototype.setHours(hour [, minute [, second [, millisecond]]]) accepts a 24-hour local hour and up to three optional time fields. When you pass only the hour, minutes, seconds, and milliseconds stay the same unless overflow normalization shifts the calendar day.
Values outside normal ranges roll forward or backward— setHours(25) becomes 1:xx on the next day. For UTC hour writes, use setUTCHours().
💡
Beginner Tip
To schedule at exactly 3:00 PM: date.setHours(15, 0, 0, 0). To add two hours: date.setHours(date.getHours() + 2).
Overflow is normalized, not rejected. That is useful for adding hours but surprising if you expected clamping to 0–23.
Applications
🚀 Common Use Cases
Meeting reminders — snap events to setHours(15, 0, 0, 0).
Business hours — open at 9, close at 17 in local time.
Relative shifts — postpone by N hours with getHours() + N.
Form time pickers — apply user-selected hour to a Date.
Day boundaries — set midnight with setHours(0, 0, 0, 0).
Clone + mutate — copy a Date before changing hours for comparisons.
🧠 How setHours() Updates the Clock
1
Read local time
Engine loads current local date and time fields.
Local
2
Apply new hour
Hour and optional minute/second/ms replace old values.
setHours
3
Normalize overflow
Out-of-range values roll into adjacent hours or days.
Normalize
4
⏱
Mutate & return ms
Date updates in place; epoch milliseconds are returned.
Important
📝 Notes
setHours() uses 24-hour local time (0 = midnight, 12 = noon).
Mutates the original Date—clone with new Date(date) when needed.
Returns epoch ms, not the Date—no fluent chaining on the return value.
Overflow normalizes (e.g. hour 25 → next day hour 1).
For real timezone conversion, use Intl or libraries—not naive getHours() + offset on UTC strings.
Use setUTCHours when rules follow UTC, not local wall clock.
Compatibility
Browser & Runtime Support
Date.prototype.setHours() has been available since ES1. It works in every browser and Node.js.
✓ Baseline · ES1
Date.prototype.setHours()
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.setHours()Excellent
Bottom line: Safe everywhere. Remember 24-hour time, mutation, and the four-argument snap pattern.
Wrap Up
Conclusion
setHours() writes the local hour (and optionally minutes, seconds, and milliseconds) on a JavaScript Date. Use it for scheduling and relative shifts; clone first when preserving the original instant.
Use setHours(15, 0, 0, 0) for exact wall-clock times
Think in 24-hour values (15 = 3 PM)
Clone before mutating shared Date instances
Pair with getHours() for relative shifts
Use setUTCHours for UTC scheduling rules
❌ Don’t
Chain setters on the numeric return value
Assume 12-hour input without converting
Treat getHours() + offset as timezone conversion
Mix local setters with UTC getters in one label
Forget midnight is hour 0, not 24
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Date.setHours()
Your foundation for local hour writes in JavaScript.
5
Core concepts
📝01
Syntax
setHours(h)
API
🕐02
0–23
24-hour.
Range
📈03
4 args
h, m, s, ms.
Overload
➕04
+ hours
getHours + n.
Pattern
🔄05
Mutates
In place.
Behavior
❓ Frequently Asked Questions
It sets the hour (0–23) of a Date object in local time. Optional arguments can also set minutes, seconds, and milliseconds. The Date mutates in place and returns updated epoch milliseconds.
getHours() reads the current local hour. setHours(h) writes a new hour. They are the read/write pair for 24-hour local time.
24-hour format. Midnight is 0, noon is 12, and 11 PM is 23. Convert for AM/PM displays yourself or use toLocaleTimeString().
JavaScript normalizes overflow into the next calendar day. setHours(25) on March 1 becomes 01:xx on March 2 (minutes/seconds unchanged unless you pass them).
Yes. setHours(hour, minute, second, millisecond) updates all four time-of-day fields at once—useful for snapping to exact times like 15:00:00.000.
setHours() changes the local clock hour. setUTCHours() changes the UTC clock hour. Use the one that matches your timezone rules.
Did you know?
setHours(15, 0, 0, 0) sets 3:00 PM exactly and clears seconds and milliseconds—hour 15 is 24-hour time, not 3 PM in a separate AM/PM field.