0

I want to add a clock to my website that displays Eastern time only. Currently I am not on EST time zone, and the clock is displaying my local time. I was unable to find a reference that does that. Some were discussing connecting to php / ajax sever time..etc which I am unfamiliar with.

Below are the html and js codes I am using.

function showTime(){
    var date = new Date();
    var h = date.getHours();
    var m = date.getMinutes();
 
    h = (h < 10) ? "0" + h : h;
    m = (m < 10) ? "0" + m : m;

    var time = h + ":" + m;
    document.getElementById("MyClockDisplay").innerText = time;
    document.getElementById("MyClockDisplay").innerContent = time;

    setTimeout(showTime, 1000);
}
    
showTime();
<body>
   <div id="MyClockDisplay"></div>
   <script src="./src/clock.js"></script>
</body>
skara9
  • 3,458
  • 1
  • 3
  • 18
ibib
  • 69
  • 3
  • 1
    Does this answer your question? [How to initialize a JavaScript Date to a particular time zone](https://stackoverflow.com/questions/15141762/how-to-initialize-a-javascript-date-to-a-particular-time-zone) – Diogo Raminhos Dec 31 '21 at 00:16

0 Answers0