How do I display milliseconds or microseconds in time?
Use Intl.DateTimeFormat to show sub-second precision in time displays
Introduction
Most time displays show hours, minutes, and seconds. This precision works for schedules, appointments, and everyday timekeeping. However, some applications require sub-second precision to display tenths, hundredths, or thousandths of a second.
Performance monitoring tools display response times in milliseconds. Scientific applications display measurements with sub-second precision. Video and audio applications display timestamps down to the millisecond. Logging systems record events with fractional second timestamps to distinguish closely spaced events.
JavaScript's Intl.DateTimeFormat provides the fractionalSecondDigits option to display sub-second precision. This lesson explains what fractional seconds are, how to display them, and when you need this level of precision.
Understanding fractional second precision
A second is the base unit of time measurement. Fractional seconds represent parts of a second smaller than one whole second.
One tenth of a second equals 0.1 seconds, which equals 100 milliseconds. This precision distinguishes events that occur within a tenth of a second of each other.
One hundredth of a second equals 0.01 seconds, which equals 10 milliseconds. This precision distinguishes events that occur within a hundredth of a second of each other.
One thousandth of a second equals 0.001 seconds, which equals 1 millisecond. This is the highest precision supported by Intl.DateTimeFormat.
JavaScript represents fractional seconds as digits after a decimal point. One digit shows tenths, two digits show hundredths, and three digits show thousandths.
About microseconds
The lesson title mentions microseconds, but Intl.DateTimeFormat does not support microsecond precision. Microseconds represent millionths of a second and would require six digits after the decimal point. The API supports a maximum of three digits, which provides millisecond precision.
JavaScript Date objects internally store time as milliseconds since January 1, 1970 UTC. This means the underlying data supports millisecond precision but not microsecond precision.
Using the fractionalSecondDigits option
The fractionalSecondDigits option controls how many digits appear after the decimal point in the seconds field. It accepts values of 1, 2, or 3.
You must include the second option when using fractionalSecondDigits. Without the second option, the formatter omits the seconds field entirely, and the fractional seconds option has no effect.
const date = new Date('2025-10-15T14:23:45.678');
const formatter = new Intl.DateTimeFormat('en-US', {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
fractionalSecondDigits: 3
});
console.log(formatter.format(date));
// Output: "2:23:45.678 PM"
This formatter displays hours, minutes, seconds, and three fractional second digits. The Date object contains millisecond precision, and the formatter displays all three digits.
Display one fractional second digit
Setting fractionalSecondDigits to 1 displays tenths of a second.
const date = new Date('2025-10-15T14:23:45.678');
const formatter = new Intl.DateTimeFormat('en-US', {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
fractionalSecondDigits: 1
});
console.log(formatter.format(date));
// Output: "2:23:45.6 PM"
The formatter rounds the value to one decimal place. The original value contains 678 milliseconds, which equals 0.678 seconds, which rounds down to 0.6 seconds when displayed with one digit.
Display two fractional second digits
Setting fractionalSecondDigits to 2 displays hundredths of a second.
const date = new Date('2025-10-15T14:23:45.678');
const formatter = new Intl.DateTimeFormat('en-US', {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
fractionalSecondDigits: 2
});
console.log(formatter.format(date));
// Output: "2:23:45.67 PM"
The formatter rounds the value to two decimal places. The value 678 milliseconds equals 0.678 seconds, which rounds down to 0.67 seconds when displayed with two digits.
Display three fractional second digits
Setting fractionalSecondDigits to 3 displays thousandths of a second, which equals milliseconds.
const date = new Date('2025-10-15T14:23:45.678');
const formatter = new Intl.DateTimeFormat('en-US', {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
fractionalSecondDigits: 3
});
console.log(formatter.format(date));
// Output: "2:23:45.678 PM"
This displays the full millisecond precision available in JavaScript Date objects. Three digits is the maximum precision supported by Intl.DateTimeFormat.
Combine with 24-hour time format
Fractional seconds work with any time formatting options, including 24-hour time format.
const date = new Date('2025-10-15T14:23:45.678');
const formatter = new Intl.DateTimeFormat('en-GB', {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
fractionalSecondDigits: 3,
hourCycle: 'h23'
});
console.log(formatter.format(date));
// Output: "14:23:45.678"
The British English locale uses 24-hour time by default, and the hourCycle option ensures 24-hour format. The fractional seconds appear after the seconds with a decimal point separator.
Include time zone with fractional seconds
You can display fractional seconds alongside time zone information.
const date = new Date('2025-10-15T14:23:45.678Z');
const formatter = new Intl.DateTimeFormat('en-US', {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
fractionalSecondDigits: 3,
timeZone: 'America/New_York',
timeZoneName: 'short'
});
console.log(formatter.format(date));
// Output: "10:23:45.678 AM EDT"
This formatter converts the UTC time to New York time and displays the result with millisecond precision and the time zone abbreviation.
How fractional seconds format across locales
Different locales use different decimal separators for numbers, but fractional seconds consistently use a period as the decimal separator across all locales.
const date = new Date('2025-10-15T14:23:45.678');
const options = {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
fractionalSecondDigits: 3
};
const en = new Intl.DateTimeFormat('en-US', options);
console.log(en.format(date));
// Output: "2:23:45.678 PM"
const de = new Intl.DateTimeFormat('de-DE', options);
console.log(de.format(date));
// Output: "14:23:45.678"
const fr = new Intl.DateTimeFormat('fr-FR', options);
console.log(fr.format(date));
// Output: "14:23:45.678"
const ar = new Intl.DateTimeFormat('ar-SA', options);
console.log(ar.format(date));
// Output: "٢:٢٣:٤٥٫٦٧٨ م"
English uses 12-hour format with AM/PM. German and French use 24-hour format. Arabic uses Arabic-Indic digits but maintains the same time format structure. All locales use a period or similar separator for the fractional seconds.
Common use cases for fractional seconds
Performance monitoring displays response times with millisecond precision.
const startTime = new Date();
// Perform operation
const endTime = new Date();
const formatter = new Intl.DateTimeFormat('en-US', {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
fractionalSecondDigits: 3,
hourCycle: 'h23'
});
console.log(`Operation completed at ${formatter.format(endTime)}`);
// Output: "Operation completed at 14:23:45.678"
This displays the exact completion time with millisecond precision for performance analysis.
Scientific data logging requires sub-second timestamps.
function logMeasurement(value) {
const timestamp = new Date();
const formatter = new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
fractionalSecondDigits: 3,
hourCycle: 'h23'
});
console.log(`${formatter.format(timestamp)} - Measurement: ${value}`);
}
logMeasurement(23.5);
// Output: "10/15/2025, 14:23:45.678 - Measurement: 23.5"
This creates timestamps with millisecond precision for scientific measurements.
Video player timestamps display position with sub-second precision.
function formatVideoTimestamp(milliseconds) {
const date = new Date(milliseconds);
const formatter = new Intl.DateTimeFormat('en-US', {
minute: '2-digit',
second: '2-digit',
fractionalSecondDigits: 2,
hourCycle: 'h23',
timeZone: 'UTC'
});
return formatter.format(date);
}
console.log(formatVideoTimestamp(125678));
// Output: "02:05.67"
This formats a video timestamp with hundredths of a second precision. Setting the time zone to UTC prevents timezone conversion for the duration value.
When to use fractional seconds
Use fractional seconds when you need to distinguish events that occur within the same second. Performance monitoring, debugging, scientific measurements, and media applications commonly require this precision.
Do not use fractional seconds for everyday timekeeping. Appointments, schedules, and user-facing timestamps rarely need sub-second precision. Adding unnecessary precision makes times harder to read and understand.
Choose the appropriate number of digits for your needs. One digit provides adequate precision for many use cases while remaining readable. Three digits provides maximum precision but creates longer, more technical-looking timestamps.
Summary
The fractionalSecondDigits option displays sub-second precision in time formatting. It accepts values of 1, 2, or 3 to display tenths, hundredths, or thousandths of a second. You must include the second option when using fractionalSecondDigits.
JavaScript's Intl.DateTimeFormat supports millisecond precision but not microsecond precision. Three fractional digits represent milliseconds, the highest precision available.
Fractional seconds work with all other time formatting options including 12-hour and 24-hour format, time zones, and different locales. The decimal separator for fractional seconds remains consistent across locales.
Use fractional seconds for performance monitoring, scientific data, debugging logs, and media timestamps. Avoid fractional seconds in everyday timekeeping where second precision suffices.