JavaScript Date getUTCMilliseconds() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
UTC ms (0–999)

What You’ll Learn

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

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.

For local sub-second reads, use getMilliseconds(). For total elapsed time, use getTime() or Date.now().

Understanding the getUTCMilliseconds() Method

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.”

📝 Syntax

JavaScript
dateObj.getUTCMilliseconds()

Parameters

  • None.

Return value

  • Integer 0–999 for a valid date in UTC.
  • NaN if dateObj is an invalid Date.

⚡ Quick Reference

GoalCode
Current UTC ms fractionnew Date().getUTCMilliseconds()
Ms from UTC partsnew Date(Date.UTC(2026, 0, 15, 10, 30, 45, 123)).getUTCMilliseconds() → 123
Local ms fractiondate.getMilliseconds()
Full epoch millisecondsdate.getTime()
Pad to three digitsString(ms).padStart(3, "0")
Valid date check!Number.isNaN(date.getTime())

📋 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

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);
Try It Yourself

How It Works

The value changes every millisecond and always stays between 0 and 999. When it would reach 1000, the UTC seconds field rolls over instead.

📈 Practical Patterns

Fixed times, validation, formatting, and duration measurement.

Example 2 — Read Milliseconds from a Fixed UTC Time

Build a date at 10:30:45.250 UTC with Date.UTC.

JavaScript
const stamp = new Date(Date.UTC(2026, 6, 4, 10, 30, 45, 250));

console.log(stamp.getUTCSeconds());        // 45
console.log(stamp.getUTCMilliseconds());   // 250
Try It Yourself

How It Works

The last argument to Date.UTC is the millisecond fraction within the UTC second. UTC getters read back the same parts everywhere.

Example 3 — Validate Before Calling getUTCMilliseconds()

Guard against invalid Date objects that yield NaN.

JavaScript
function safeGetUTCMilliseconds(date) {
  if (!(date instanceof Date) || Number.isNaN(date.getTime())) {
    return null;
  }
  return date.getUTCMilliseconds();
}

console.log(safeGetUTCMilliseconds(new Date()));              // e.g. 512
console.log(safeGetUTCMilliseconds(new Date("not-a-date")));  // null
Try It Yourself

How It Works

instanceof Date alone is not enough—invalid dates are still Date objects. Always check getTime() for NaN.

Example 4 — Format UTC Seconds with Milliseconds

Pad the UTC millisecond value to three digits for log-style output.

JavaScript
function formatUtcSecondsWithMs(date) {
  const sec = date.getUTCSeconds();
  const ms = String(date.getUTCMilliseconds()).padStart(3, "0");
  return sec + "." + ms + "s UTC";
}

console.log(formatUtcSecondsWithMs(
  new Date(Date.UTC(2026, 6, 4, 10, 30, 7, 5))
));
// "7.005s UTC"
Try It Yourself

How It Works

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");
Try It Yourself

How It Works

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.

🚀 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.

📝 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.

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 Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Date.getUTCMilliseconds() Excellent

Bottom line: Safe everywhere. Remember it reads sub-second UTC fractions—not elapsed time or epoch milliseconds.

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.

Next, learn getUTCMinutes() for the UTC minute component, or review getMilliseconds() for local sub-second reads.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about Date.getUTCMilliseconds()

Your foundation for UTC sub-second reads in JavaScript.

5
Core concepts
🔢 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.

Continue to getUTCMinutes()

Learn how to read the minute component (0–59) from a Date in UTC.

getUTCMinutes() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful