<div id="time"></div>
function setTimer(el, template) {
return clearInterval.bind(null, 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 stop = setTimer('#time', '<strong>Сейчас</strong> $h:$m:$s');
// если вдруг понадобится остановить вывод времени, делаете так: stop();