JSFiddle - React, Tailwind, and code Playground

by Dmytro Dzyubak

HTML

<div id="clock"></div>

JavaScript

function addLeadingZero(n) {
    return n < 10 ? '0' + n : n;
}

function windTheClock(timeZoneOffset)
{
    var d = new Date();
    d.setHours(d.getUTCHours() + timeZoneOffset); // set time zone offset
    var h = d.getHours();
    var m = d.getMinutes();
    var s = d.getSeconds();
    var ampm = h >= 12 ? 'pm' : 'am';
    h = h % 12;
    h = h ? h : 12; // replace '0' w/ '12'
    h = addLeadingZero(h);
    m = addLeadingZero(m);
    s = addLeadingZero(s);

    document.all["clock"].innerHTML = h + ':' + m + ':' + s
        + ' ' + ampm;
    setTimeout(function(){ windTheClock(timeZoneOffset) }, 1000);
}

window.onload = function() {
    windTheClock(2);
}