JSFiddle - React, Tailwind, and code Playground

by jeykeu

HTML

<p>Start time: <span id="start_time"></span></p>
<p>Current time: <span id="current_time"></span></p>
<p>Elapsed milli-seconds: <span id="elapsed"></span></p>

JavaScript

//http://stackoverflow.com/users/995958/lorenzo-s
// Get and display start time
var startTime = new Date();
document.getElementById('start_time').innerHTML = startTime;

// Periodical function
window.updateTime = function() {
    
    // Get and display current time
    var currentTime = new Date();
    document.getElementById('current_time').innerHTML = currentTime;
    
    // Calculate and display elapsed milliseconds
    var elapsedTimeInMs = currentTime.getTime() - startTime.getTime();
    document.getElementById('elapsed').innerHTML = elapsedTimeInMs;
    
}

// Set periodical execution of previously declared function
setInterval('window.updateTime()', 100); // Every 100ms