JavaScript Date getMilliseconds() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Date

Definition

Date.prototype.getMilliseconds() returns the millisecond fraction of the current second as an integer 0–999 in local time. It is read-only and does not change the Date.

Remember
date.getMilliseconds()

0   = start of the second
123 = 123 ms into the second
999 = last millisecond of the second

→ integer 0 … 999
→ NaN if the Date is invalid

getMilliseconds() → 0–999 fraction
getTime()         → ms since 1970-01-01 UTC

Syntax

Call date.getMilliseconds. Start with this line.

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

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

Library declarations
JavaScript
date.getMilliseconds()

Parameters

ParameterDescription
PaddingOptional. Use padStart(3, "0") for .123-style display

Return Value

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

JavaScript Examples

Example 1 — Read the Millisecond Fraction

Call getMilliseconds() when ms are set — and when they default to 0.

JavaScript
const withMs = new Date(2026, 0, 1, 12, 0, 0, 456);
const xmas = new Date(1995, 11, 25, 23, 15, 30); // ms omitted

console.log(withMs.getMilliseconds()); // 456
console.log(xmas.getMilliseconds());   // 0
Try It Yourself

How It Works

  1. Pass ms in the constructor. The 7th argument is milliseconds (456).
  2. Read the field. getMilliseconds() returns that 0–999 value.
  3. Omitted ms. Building a time without ms usually stores 0.
  4. Local time. The getter follows local calendar fields for that Date.

Example 2 — setMilliseconds then getMilliseconds

Match the MDN pattern: write a millisecond value, then read it back.

JavaScript
const moonLanding = new Date(1969, 6, 20, 0, 20, 18);
moonLanding.setMilliseconds(123);

console.log(moonLanding.getMilliseconds()); // 123
Try It Yourself

How It Works

  1. Start with a local date-time. July is month index 6.
  2. Write the fraction. setMilliseconds(123) stores 123.
  3. Read it back. getMilliseconds() returns 123.
  4. Range reminder. Values stay in 0–999 (overflow carries to seconds).

Example 3 — getMilliseconds() vs getTime()

Do not confuse the 0–999 field with epoch milliseconds.

JavaScript
const d = new Date(2026, 0, 1, 12, 0, 0, 456);

console.log(d.getMilliseconds());     // 456
console.log(d.getTime() % 1000);      // 456 (last three digits)
console.log(d.getTime() > 1000);      // true — full epoch value
Try It Yourself

How It Works

  1. Fraction getter. getMilliseconds() is just 456.
  2. Epoch remainder. getTime() % 1000 often matches that fraction.
  3. Full timeline. getTime() itself is a huge number (ms since 1970).
  4. Measuring gaps. Subtract getTime() values — never use the 0–999 field alone.

Browser & Runtime Support

Date.prototype.getMilliseconds() is part of the language from early ECMAScript and is Baseline Widely available (MDN).

✓ Baseline · Widely available

Date.prototype.getMilliseconds()

Supported in every modern browser and Node.js. No polyfill needed for ordinary web apps.

99% Modern browser support
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.getMilliseconds() Excellent

Bottom line: Safe everywhere. Focus on choosing getMilliseconds vs getTime correctly rather than feature detection.

Frequently Asked Questions

An integer from 0 to 999 for the milliseconds within the current second in local time. It is not the total milliseconds since 1970 — that is getTime().
getMilliseconds() returns the 0–999 sub-second fraction. getTime() returns the full epoch milliseconds since January 1, 1970 UTC.
getMilliseconds() uses local time. getUTCMilliseconds() uses UTC. For most instants they match; prefer the UTC getter when your code is timezone-agnostic.
NaN. Validate with Number.isNaN(date.getTime()) before using the result.
No. Subtract getTime() values, or use Date.now() / performance.now(). getMilliseconds() only reads the fraction inside one second.
No. The range is 0–999. Overflow carries into the seconds field automatically.

Next: getTime()

Learn how to read milliseconds since the Unix epoch from a Date.

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