HTML Digital Clock? (specific timezone)
Go to solution
Solved by Nettly_,
1 hour ago, ughiwanthackintosh said:if i google it alot of free "widgets" sites popup, but they have bad clocks with either a script that if i click the clock it takes me there.
or they simply just dont work
How can i make a HTML Digital Clock? For Haugesund Norway?
Please suggest code
![]()
Now I am going to be honest I did steal the code I am about to show you from Stackoverflow and W3Schools but I am too lazy to make up my own code right now.
<body onload="startTime()"> <h1 id="time"></h1> <script> function startTime() { var today = new Date(); var h = today.getHours(); var m = today.getMinutes(); var s = today.getSeconds(); m = checkTime(m); s = checkTime(s); document.getElementById('time').innerHTML = h + ":" + m + ":" + s; var t = setTimeout(startTime, 500); } function checkTime(i) { if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10 return i; } </script> </body>
So in an actual app it might look like something like this
<body onload="startTime()"> <h1>The time:</h1> <p id="time"></p> <script> function startTime() { var today = new Date(); var h = today.getHours(); var m = today.getMinutes(); var s = today.getSeconds(); m = checkTime(m); s = checkTime(s); document.getElementById('time').innerHTML = h + ":" + m + ":" + s; var t = setTimeout(startTime, 500); } function checkTime(i) { if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10 return i; } </script> <style> h1,p{ font-family: arial; text-align: center; } </style> </body>
and the actual clock looks like
Then add whatever you want.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now