JavaScript Date setUTCMilliseconds() Method

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

What You’ll Learn

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

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.

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.

For local sub-second writes, use setMilliseconds(). For a full UTC time including ms in one call, use setUTCHours(h, m, s, ms).

💡
Beginner Tip

Verify with toISOString()—the digits after the decimal before Z are UTC milliseconds (e.g. .500Z = 500 ms).

📝 Syntax

JavaScript
dateObj.setUTCMilliseconds(millisecondsValue)

Parameters

  • millisecondsValue — Integer for the UTC sub-second fraction (typically 0–999; overflow normalizes).

Return value

  • Updated epoch milliseconds after the change.
  • NaN if the Date was invalid before the call.

⚡ Quick Reference

GoalCode
Set UTC ms to 500date.setUTCMilliseconds(500)
Zero UTC sub-secondsdate.setUTCMilliseconds(0)
Read UTC ms after setdate.getUTCMilliseconds()
Set h m s ms at once (UTC)date.setUTCHours(h, m, s, ms)
Local ms setterdate.setMilliseconds(500)
Verify ISO outputdate.toISOString()

📋 setUTCMilliseconds() vs Similar Methods

These APIs involve milliseconds but serve different jobs.

setUTCMilliseconds()
UTC 0–999

UTC sub-second

getUTCMilliseconds()
read

Getter pair

setMilliseconds()
local 0–999

Local setter

getTime()
epoch ms

Full timestamp

Examples Gallery

Open DevTools Console (F12) or use Try-it links. Examples use Date.UTC() for predictable UTC times.

📚 Getting Started

Change the UTC millisecond fraction inside the current second.

Example 1 — Set UTC Milliseconds to 500

Update only the UTC sub-second part; UTC seconds and above stay the same.

JavaScript
const date = new Date(Date.UTC(2026, 2, 1, 12, 30, 45, 120));
date.setUTCMilliseconds(500);

console.log(date.getUTCSeconds());         // 45
console.log(date.getUTCMilliseconds());    // 500
console.log(date.toISOString());           // "2026-03-01T12:30:45.500Z"
Try It Yourself

How It Works

UTC milliseconds are the fraction inside the current UTC second—not total ms since 1970.

📈 Practical Patterns

Zero noise, combined setters, immutable style, and overflow.

Example 2 — Zero Out UTC Sub-Second Precision

Round a timestamp down to whole UTC seconds for ISO display.

JavaScript
const date = new Date(Date.UTC(2026, 2, 1, 12, 30, 45, 789));
date.setUTCMilliseconds(0);

console.log(date.getUTCSeconds());         // 45
console.log(date.getUTCMilliseconds());    // 0
console.log(date.toISOString());           // "2026-03-01T12:30:45.000Z"
Try It Yourself

How It Works

Useful before second-granularity UTC comparisons or when you need clean .000Z ISO strings.

Example 3 — Set Milliseconds via setUTCHours(h, m, s, ms)

When you need the full UTC time including ms, the four-argument overload is often clearer.

JavaScript
const date = new Date(Date.UTC(2026, 2, 1, 9, 0, 0, 0));
date.setUTCHours(12, 30, 45, 250);

console.log(date.getUTCHours());           // 12
console.log(date.getUTCMilliseconds());    // 250
console.log(date.toISOString());           // "2026-03-01T12:30:45.250Z"
Try It Yourself

How It Works

setUTCHours() accepts ms as its fourth argument when you want one coordinated UTC update.

Example 4 — Clone, Then Set (Immutable Style)

Preserve the original Date by copying before mutating UTC milliseconds.

JavaScript
const original = new Date(Date.UTC(2026, 2, 1, 12, 30, 45, 100));
const adjusted = new Date(original);
adjusted.setUTCMilliseconds(750);

console.log("Original ms:", original.getUTCMilliseconds());  // 100
console.log("Adjusted ms:", adjusted.getUTCMilliseconds());  // 750
Try It Yourself

How It Works

Setters always mutate their target. Clone first when other code still needs the old instant.

Example 5 — UTC Millisecond Overflow (setUTCMilliseconds(1500))

Values above 999 roll into the next UTC second.

JavaScript
const date = new Date(Date.UTC(2026, 2, 1, 12, 30, 45, 0));
date.setUTCMilliseconds(1500);

console.log(date.getUTCSeconds());         // 46
console.log(date.getUTCMilliseconds());    // 500
Try It Yourself

How It Works

1500 ms = 1 UTC second + 500 ms. The engine normalizes instead of clamping to 999.

🚀 Common Use Cases

  • ISO timestamps — align fractional seconds in toISOString() output.
  • UTC second roundingsetUTCMilliseconds(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.

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

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 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.setUTCMilliseconds() Excellent

Bottom line: Safe everywhere. Remember sub-second vs epoch ms, mutation, and UTC vs local setters.

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.

Next, learn setUTCMinutes() to change the UTC minute field, or review getUTCMilliseconds() for reading the UTC fraction.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about Date.setUTCMilliseconds()

Your foundation for UTC sub-second writes in JavaScript.

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

Continue to setUTCMinutes()

Learn how to set the UTC minute field (0–59) on a Date object.

setUTCMinutes() 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