Example 1 — Read the Millisecond Fraction
Call getMilliseconds() when ms are set — and when they default to 0.
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 How It Works
- Pass ms in the constructor. The 7th argument is milliseconds (
456). - Read the field.
getMilliseconds()returns that 0–999 value. - Omitted ms. Building a time without ms usually stores
0. - Local time. The getter follows local calendar fields for that
Date.

