A simple clock to show on screen

tools
Published

June 17, 2025

TL;DR; The result is here

At the University, we forbid the use of smartphones or smartwatches during exams, most of the students do not have a classical wrist watch, and most of the classrooms do not have a clock either. Therefore, I did a clock in pure html that we can show on a beamer. It should work in any browser.

There are some room for improvements that I might implement some day:

Here is the code:


<!DOCTYPE html>
<html>

<body onload="startTime()">
<div style="height:15vw;"></div>
<div id="txt" style="display:block;width:100%;font-size:10vw;text-align:center;font-family:sans-serif;"></div>

<script>
function startTime() {
  const today = new Date();
  let h = today.getHours();
  let m = today.getMinutes();
  let s = today.getSeconds();
  m = checkTime(m);
  s = checkTime(s);
  document.getElementById('txt').innerHTML =  h + ":" + m + ":" + s;
  setTimeout(startTime, 1000);
}

function checkTime(i) {
  if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
  return i;
}
</script>

</body>
</html>