getUTCMilliseconds() returns the millisecond fraction (0–999) within the current UTC second from a Date object. This guide covers syntax, five examples, comparisons with related APIs, and safe UTC time patterns.
01
Syntax
date.getUTCMilliseconds()
02
Range
0 – 999
03
UTC
Sub-second
04
Not getTime
Not epoch
05
Format
Pad to 3
06
Validate
Invalid → NaN
Fundamentals
Introduction
High-precision logs and APIs sometimes need sub-second detail in UTC. The JavaScript Date object stores one instant internally; getUTCMilliseconds() reads only the millisecond fraction inside the current UTC second—not the full timestamp.
Date.prototype.getUTCMilliseconds() is a zero-argument instance method. It never mutates the original Date—it only reads the UTC millisecond component as an integer from 0 to 999.
Pair it with getUTCSeconds(), getUTCMinutes(), and getUTCHours() to assemble UTC time parts, or use toISOString() when a full UTC string is enough.
💡
Beginner Tip
getUTCMilliseconds() is not epoch milliseconds. A value like 250 means “250 ms into the current UTC second,” not “250 ms since 1970.”
Foundation
📝 Syntax
JavaScript
dateObj.getUTCMilliseconds()
Parameters
None.
Return value
Integer 0–999 for a valid date in UTC.
NaN if dateObj is an invalid Date.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Current UTC ms fraction
new Date().getUTCMilliseconds()
Ms from UTC parts
new Date(Date.UTC(2026, 0, 15, 10, 30, 45, 123)).getUTCMilliseconds() → 123
Local ms fraction
date.getMilliseconds()
Full epoch milliseconds
date.getTime()
Pad to three digits
String(ms).padStart(3, "0")
Valid date check
!Number.isNaN(date.getTime())
Compare
📋 getUTCMilliseconds() vs Similar Methods
These APIs sound similar but answer different questions. Pick the one that matches your task.
getUTCMilliseconds()
0–999
UTC sub-second
getMilliseconds()
local
Local sub-second
getTime()
epoch ms
Full instant
getUTCSeconds()
0–59
UTC whole seconds
Hands-On
Examples Gallery
Open DevTools Console (F12) or use Try-it links. Fixed UTC times use Date.UTC with a millisecond argument for predictable results.
📚 Getting Started
Read the UTC millisecond fraction from the current time.
Example 1 — Get the Current UTC Millisecond Fraction
Call getUTCMilliseconds() on the current instant.
JavaScript
const now = new Date();
const ms = now.getUTCMilliseconds();
console.log("UTC milliseconds:", ms);
padStart(3, "0") turns 5 into "005" so the fractional part keeps a fixed width in logs and UI.
Example 5 — Measure Elapsed Time (Use getTime(), Not getUTCMilliseconds())
For duration between two moments, subtract epoch milliseconds.
JavaScript
const start = Date.now();
// Simulate work
let sum = 0;
for (let i = 0; i < 100000; i++) {
sum += i;
}
const elapsed = Date.now() - start;
console.log("Elapsed:", elapsed, "ms");
getUTCMilliseconds() only reads 0–999 inside one UTC second. Subtracting two getUTCMilliseconds() values does not measure elapsed time across seconds—use Date.now() or getTime() instead.
Applications
🚀 Common Use Cases
UTC log timestamps — append sub-second precision in UTC.
API debugging — inspect millisecond parts of ISO strings.
Manual UTC formatting — build HH:MM:SS.mmm with UTC getters.
Test fixtures — assert sub-second parts from Date.UTC.
Event ordering — tie-break events within the same UTC second.
Education — teach UTC getters before using toISOString().
🧠 How getUTCMilliseconds() Resolves the Fraction
1
Internal instant
The Date stores milliseconds since Unix epoch (UTC).
Storage
2
UTC projection
Engine reads UTC time fields, including the current second.
UTC
3
Extract fraction
Millisecond part within that UTC second (0–999) is returned.
getUTCMilliseconds
4
🌐
Format or compare
Pad for logs or pair with other UTC getters—not for elapsed timers.
Important
📝 Notes
getUTCMilliseconds() returns 0–999, not epoch milliseconds.
Do not subtract two getUTCMilliseconds() values to measure duration.
Invalid dates propagate NaN—validate with Number.isNaN(date.getTime()).
For benchmarking, prefer Date.now() or performance.now().
For full UTC strings, toISOString() is often simpler than manual getters.
Use UTC getters together when building UTC time labels.
Compatibility
Browser & Runtime Support
Date.prototype.getUTCMilliseconds() has been available since the first JavaScript Date implementation (ES1). It works in every browser and Node.js.
✓ Baseline · ES1
Date.prototype.getUTCMilliseconds()
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.getUTCMilliseconds()Excellent
Bottom line: Safe everywhere. Remember it reads sub-second UTC fractions—not elapsed time or epoch milliseconds.
Wrap Up
Conclusion
getUTCMilliseconds() reads the 0–999 fraction within the current UTC second. Use it for UTC formatting and inspection; use getTime() or Date.now() for elapsed duration.
Validate dates before calling getUTCMilliseconds()
Pad to three digits when formatting logs
Use getTime() for elapsed duration
Prefer Date.UTC in tests for stable fixtures
Pair with other UTC getters for manual labels
❌ Don’t
Confuse with getTime() epoch milliseconds
Subtract getUTCMilliseconds() values for timers
Clamp 0–999 manually on valid dates
Expect values above 999
Ignore NaN from bad date parses
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Date.getUTCMilliseconds()
Your foundation for UTC sub-second reads in JavaScript.
5
Core concepts
📝01
Syntax
date.getUTCMilliseconds()
API
🔢02
0–999
Sub-second.
Range
🌐03
UTC
Not epoch.
Timezone
⏱04
Pad 3
Log format.
Format
⚠05
Not elapsed
Use getTime().
Pitfall
❓ Frequently Asked Questions
An integer from 0 to 999 representing the milliseconds within the current UTC second—not the total milliseconds since 1970.
getUTCMilliseconds() returns 0–999 for the sub-second fraction in UTC. getTime() returns the full count of milliseconds since the Unix epoch.
getUTCMilliseconds() reads the UTC second's fractional part. getMilliseconds() reads the local second's fractional part. For most instants they match, but they can differ when UTC and local seconds are not aligned.
NaN. Validate with Number.isNaN(date.getTime()) before using the result.
No. For durations between two moments, subtract getTime() values or use Date.now() and performance.now(). getUTCMilliseconds() only reads 0–999 inside one UTC second.
No. The range is 0–999. When milliseconds overflow, JavaScript carries into the UTC seconds field automatically.
Did you know?
Subtracting end.getUTCMilliseconds() - start.getUTCMilliseconds() does not measure how long an operation took—use Date.now() - start for real elapsed milliseconds.