A simple clock to show on screen
tools
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:
- add a starting time and end time
- add several time periods (some exams define a specific time for each part)
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();
= checkTime(m);
m = checkTime(s);
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>