(function(){ function updateTimeVars() { var d = new Date(); var css = ':root { ' + '--hour: ' + d.getHours() + '; ' + '--minute: ' + d.getMinutes() + '; ' + '--second: ' + d.getSeconds() + '; ' + '--ms: ' + d.getMilliseconds() + '; ' + '--ns: ' + Math.floor(d.getMilliseconds() * 1e6) + '; ' + '}'; if (!window.__timeStyle) { var style = document.createElement('style'); style.type = 'text/css'; document.head.appendChild(style); window.__timeStyle = style; } window.__timeStyle.innerHTML = css; } // Initial update updateTimeVars(); // Update every 50ms for smooth milliseconds and nanoseconds setInterval(updateTimeVars, 50); })();