JSFiddle - React, Tailwind, and code Playground
HTML
<canvas id='clock' width='300px' height='300px'>
JavaScript
function init(){
clock();
setInterval(clock,1000);
}
function clock(){
var now = new Date();
var size = 1;
var ctx = document.getElementById('clock').getContext('2d');
ctx.save();
ctx.clearRect(0,0,300*size,300*size);
ctx.translate(150*size,150*size);
ctx.scale(size,size);
ctx.rotate(-Math.PI/2);
ctx.strokeStyle = "grey";
ctx.fillStyle = "black";
ctx.lineWidth = 8;
ctx.lineCap = "butt";
// background
ctx.beginPath();
ctx.lineWidth = 2;
ctx.fillStyle = "#EFEFEF";
ctx.arc(0,0,120,0,Math.PI*2,true);
ctx.fill();
var sec = now.getSeconds();
var min = now.getMinutes();
var hr= now.getHours();
hr = hr>=12 ? hr-12 : hr;
// write Hours
ctx.save();
ctx.rotate( hr*(Math.PI/6) + (Math.PI/360)*min + (Math.PI/21600)*sec );
ctx.strokeStyle = "black";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(-20,0);
ctx.lineTo(80,0);
ctx.stroke();
ctx.lineWidth = 6;
ctx.beginPath();
ctx.moveTo(-20,0);
ctx.lineTo(80,0);
ctx.stroke();
ctx.restore();
// write Minutes
ctx.save();
ctx.rotate( (Math.PI/30)*min + (Math.PI/1800)*sec );
ctx.strokeStyle = "black";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(-20,0);
ctx.lineTo(110,0);
ctx.stroke();
ctx.lineWidth = 6;
ctx.beginPath();
ctx.moveTo(-20,0);
ctx.lineTo(110,0);
ctx.stroke();
ctx.restore();
ctx.beginPath();
ctx.lineWidth = 2;
ctx.strokeStyle = '#000000';
ctx.arc(0,0,120,0,Math.PI*2,true);
ctx.restore();
}
window.onload = function(e){init()}