Jump to content

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
image.png.6c30ca114d55e4b682d43ccddac75647.png

Then add whatever you want.

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 ?

 

Link to comment
https://linustechtips.com/topic/1105001-html-digital-clock-specific-timezone/
Share on other sites

Link to post
Share on other sites

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
image.png.6c30ca114d55e4b682d43ccddac75647.png

Then add whatever you want.

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×