Millisecond Clock

Watch time fly. Literally. This clock refreshes dozens of times per second to display the current time including the rapidly changing millisecond counter.

00:00:00.000

Copy the Script

<div id="timer"></div>

<script>
function updateMs() {
    var d = new Date();
    var h = d.getHours();
    var m = d.getMinutes();
    var s = d.getSeconds();
    var ms = d.getMilliseconds();
    
    // Formatting
    m = (m < 10) ? "0"+m : m;
    s = (s < 10) ? "0"+s : s;
    ms = (ms < 100) ? "0"+ms : ms; // Pad 2 zeros if needed (e.g. 050)
    if(ms < 10) ms = "00"+ms;

    document.getElementById("timer").innerText = h + ":" + m + ":" + s + "." + ms;
}

// Update every 20 milliseconds
setInterval(updateMs, 20);
</script>

Frequently Asked Questions

Updating the DOM every millisecond (1ms) is often too fast for screens to render (which are usually 60Hz). It is better to update every 10-20ms for smooth visuals without wasting CPU.

Yes. This is the exact logic used for race timers and stopwatches where fractions of a second matter.

Standard JavaScript `getMilliseconds()` returns 0 to 999 (3 digits).