JavaScript Date setUTCMilliseconds() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Date

Definition

Date.prototype.setUTCMilliseconds() changes the milliseconds (0–999) of a Date in UTC. It mutates the date in place and returns the new epoch timestamp.

Remember
date.setUTCMilliseconds(millisecondsValue)

millisecondsValue → 0–999 (UTC sub-second)
overflow          → rolls into the next UTC second
returns           → epoch milliseconds (or NaN)

setUTCMilliseconds() → UTC fraction
setMilliseconds()    → local fraction

Syntax

Call date.setUTCMilliseconds. Start with this line.

JavaScript
date.setUTCMilliseconds(ms)
CallWhat it does
date.setUTCMilliseconds(ms)Primary signature.
date.setUTCMilliseconds(...)Call with the arguments your case needs.

Built into JavaScript. Call setUTCMilliseconds(...) on a Date instance — no import required.

Library declarations
JavaScript
date.setUTCMilliseconds(ms)

Parameters

ParameterDescription
millisecondsValueRequired. UTC ms (0–999; overflow allowed)

Return Value

Return ValueDescription
*The value returned by date.setUTCMilliseconds().

JavaScript Examples

Example 1 — Set UTC Milliseconds

Change only the .mmm part of a UTC timestamp.

JavaScript
const date = new Date("2018-01-24T12:38:29.069Z");

console.log(date.getUTCMilliseconds()); // 69
date.setUTCMilliseconds(420);
console.log(date.getUTCMilliseconds()); // 420
console.log(date.toISOString());        // "2018-01-24T12:38:29.420Z"
Try It Yourself

How It Works

  1. Parse a UTC ISO string. The date starts at .069 milliseconds.
  2. Read the fraction. getUTCMilliseconds() returns 69.
  3. Write a new value. setUTCMilliseconds(420) replaces only the ms field.
  4. Confirm ISO. Hours/minutes/seconds stay the same; the string ends in .420Z.

Example 2 — Zero UTC Sub-Second Precision

Snap to a whole UTC second by clearing milliseconds.

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

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

How It Works

  1. Start with a fraction. Date.UTC(..., 250) builds .250Z.
  2. Clear ms. setUTCMilliseconds(0) writes zero.
  3. Keep the second. The UTC second stays 45; only the fraction changes.
  4. Why it helps. Useful when APIs or logs should show whole-second UTC times.

Example 3 — Millisecond Overflow (setUTCMilliseconds(1500))

Values past 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
console.log(date.toISOString());        // "2026-03-01T12:30:46.500Z"
Try It Yourself

How It Works

  1. Start at second 45. Milliseconds begin at 0.
  2. Pass 1500. That is 1 full second plus 500 ms.
  3. Normalize. Seconds become 46, milliseconds become 500.
  4. Use carefully. Overflow helps when adding ms, but it will not reject bad input.

Browser & Runtime Support

Date.prototype.setUTCMilliseconds() has been in JavaScript since ES1. It is Baseline and works in every modern browser and Node.js — no polyfill needed.

✓ Baseline · ES1

Date.prototype.setUTCMilliseconds()

Supported everywhere Date exists: Chrome, Firefox, Safari, Edge, Internet Explorer, and all Node.js versions.

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 to use in any environment. Remember UTC vs local, mutation, and overflow into seconds. See also the MDN setUTCMilliseconds() reference.

Frequently Asked Questions

It sets the milliseconds within the current UTC second (0–999) on a Date. The Date mutates in place and returns the new timestamp in milliseconds.
setMilliseconds() changes the local sub-second fraction. setUTCMilliseconds() changes the UTC sub-second fraction. Use the setter that matches your timezone rules.
JavaScript normalizes overflow. 1500 ms becomes 1 UTC second plus 500 ms—the UTC seconds field increments and milliseconds become 500.
No. It returns a number (epoch milliseconds), or NaN if the date becomes invalid. Call each setter on the same Date variable—do not chain on the return value.
setUTCMilliseconds() only changes the 0–999 fraction inside the current UTC second (with overflow). getTime() returns the full epoch milliseconds since 1970—use getTime() for elapsed duration.
Use it to align ISO/UTC precision (for example zero the .mmm part) or set a specific UTC sub-second value. Prefer setMilliseconds() for local wall-clock precision.

Next: setUTCMinutes()

Learn how to set the UTC minutes (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.

11 people found this page helpful