setUTCMilliseconds() writes the sub-second fraction (0–999) inside the current UTC second. This guide covers syntax, ISO precision, overflow, and comparisons with local setMilliseconds() and getTime().
01
Syntax
setUTCMilliseconds(ms)
02
0–999 UTC
Sub-second
03
Not getTime
Clock fraction
04
Zero ms
.000Z snap
05
Overflow
Rolls seconds
06
Returns
Epoch ms
Fundamentals
Introduction
ISO timestamps and server logs often include fractional seconds. After reading the UTC fraction with getUTCMilliseconds(), setUTCMilliseconds() writes it back without touching local timezone offsets.
This is not the same as setting total epoch time—that is setTime() or getTime(). Here you adjust only the millisecond hand inside the current UTC second.
Concept
Understanding the setUTCMilliseconds() Method
Date.prototype.setUTCMilliseconds(millisecondsValue) accepts an integer for the UTC sub-second fraction. Values outside 0–999 normalize into adjacent UTC seconds instead of being rejected.
1500 ms = 1 UTC second + 500 ms. The engine normalizes instead of clamping to 999.
Applications
🚀 Common Use Cases
ISO timestamps — align fractional seconds in toISOString() output.
UTC second rounding — setUTCMilliseconds(0) before second-level compare.
Test fixtures — pin exact UTC ms in unit tests with Date.UTC().
Log alignment — normalize sub-second noise in server log timestamps.
Animation timing — fine-tune UTC sub-second fields in frame loops.
Clone + mutate — copy a Date before changing UTC milliseconds.
🧠 How setUTCMilliseconds() Updates the UTC Clock
1
Read UTC time
Engine loads current UTC second and millisecond fields.
UTC
2
Apply new ms
The millisecond value replaces the old UTC fraction.
setUTCMilliseconds
3
Normalize overflow
Values ≥ 1000 roll into the next UTC second.
Normalize
4
🌐
Mutate & return ms
Date updates in place; epoch milliseconds are returned.
Important
📝 Notes
setUTCMilliseconds() adjusts the fraction inside the current UTC second (0–999 typical range).
Not the same as setTime(epochMs), which replaces the entire instant.
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 (1500 → next UTC second + 500 ms).
Use setMilliseconds for local clocks; setUTCMilliseconds for ISO/server rules.
Compatibility
Browser & Runtime Support
Date.prototype.setUTCMilliseconds() has been available since ES1. It works in every browser and Node.js.
✓ Baseline · ES1
Date.prototype.setUTCMilliseconds()
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.setUTCMilliseconds()Excellent
Bottom line: Safe everywhere. Remember sub-second vs epoch ms, mutation, and UTC vs local setters.
Wrap Up
Conclusion
setUTCMilliseconds() writes the UTC sub-second fraction (0–999) on a JavaScript Date. Use it for ISO-aligned precision; use setMilliseconds() for local wall clocks.
Use setUTCMilliseconds(0) to snap ISO strings to whole UTC seconds
Verify with toISOString() after changes
Pair with getUTCMilliseconds() for read/write workflows
Clone before mutating shared Date instances
Use Date.UTC() when building test fixtures
❌ Don’t
Confuse sub-second ms with total epoch ms from getTime()
Mix setUTCMilliseconds with getMilliseconds() in one step
Chain setters on the numeric return value
Assume values clamp at 999 (overflow rolls seconds)
Use local setters when ISO UTC rules apply
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Date.setUTCMilliseconds()
Your foundation for UTC sub-second writes in JavaScript.
5
Core concepts
📝01
Syntax
setUTCMilliseconds(ms)
API
🌐02
0–999 UTC
Sub-second.
Range
🔢03
Not getTime
Clock fraction.
Distinction
📈04
Zero ms
.000Z snap.
Pattern
🔄05
Mutates
In place.
Behavior
❓ Frequently Asked Questions
It sets the milliseconds within the current UTC second (0–999) on a Date object. The Date mutates in place and returns updated epoch milliseconds.
getUTCMilliseconds() reads the UTC sub-second fraction (0–999). setUTCMilliseconds(ms) writes it. They are the read/write pair for the millisecond hand of the UTC clock.
setUTCMilliseconds() changes only the 0–999 fraction inside the current UTC second (with overflow rules). getTime() returns the full epoch milliseconds since 1970—use getTime() for elapsed duration.
JavaScript normalizes overflow. 1500 ms becomes 1 UTC second and 500 ms—the UTC seconds field increments and milliseconds become 500.
No. It returns a number (epoch milliseconds). Call each setter on the same Date variable—do not chain on the return value.
setUTCMilliseconds() changes the UTC sub-second fraction. setMilliseconds() changes the local sub-second fraction. Use the one that matches your timezone rules.
Did you know?
setUTCMilliseconds(500) changes the digits after the decimal in toISOString() to .500Z—the same instant may show a different local millisecond in getMilliseconds() when your timezone offset is not a whole number of hours.