<div id="time"></div>
function setTimer(el, template) {
return setInterval(el => {
const d = new Date();
const timeData = Object.fromEntries([
[ 'h', 'getHours' ],
[ 'm', 'getMinutes' ],
[ 's', 'getSeconds' ],
].map(n => [ n[0], `${d[n[1]]()}`.padStart(2, 0) ]));
el.innerHTML = template.replace(
/\$(\w)/g,
(m, g1) => timeData.hasOwnProperty(g1) ? timeData[g1] : m
);
}, 1000, typeof el === 'string' ? document.querySelector(el) : el);
}
const intervalId = setTimer('#time', '<strong>Сейчас</strong> $h:$m:$s');