console
var hourspan =document.getElementById("hour");
var minutespan =document.getElementById("minute");
var secondspan =document.getElementById("second");
var dom = document.getElementById("clock");
var ctx = dom.getContext("2d");
var width = ctx.canvas.width;
var height = ctx.canvas.height;
var r = width/2;
function drawBackground(){
ctx.save();
ctx.translate(r,r);
ctx.beginPath();
ctx.lineWidth = 10;
var grd = ctx.createLinearGradient(-120,-120,0,0);
grd.addColorStop(0, "rgb(120,120,120)");
grd.addColorStop(1, "rgb(30,30,30)");
ctx.strokeStyle = grd;
ctx.arc(0,0,r-8,0,2*Math.PI,false);
ctx.stroke();
ctx.beginPath();
ctx.lineWidth = 16;
var grd = ctx.createRadialGradient(0,0,r-24, 0,0,r+5);
grd.addColorStop(0, "rgb(243,245,246)");
grd.addColorStop(1, "rgb(150, 150, 150)");
ctx.strokeStyle = grd;
ctx.arc(0,0,r-20,0,2*Math.PI,false);
ctx.stroke();
for(var i=0;i<60;i++){
var rad = 2*Math.PI/60*i;
var x = Math.cos(rad)*(r-26);
var y = Math.sin(rad)*(r-26);
ctx.beginPath();
ctx.arc(x,y,3,0,Math.PI*2,false);
if(i%5 == 0){
ctx.fillStyle = "#ddd";
ctx.fill();
}
}
}
function drawHour(hour,minute,second){
ctx.save();
ctx.beginPath();
var rad = 2*Math.PI/12*hour+((2*Math.PI/12)*(minute+second/60)/60);
ctx.rotate(rad);
ctx.strokeStyle = "#000";
ctx.lineWidth = 8;
ctx.lineCap = "round";
ctx.moveTo(0,10);
ctx.lineTo(0,-r/2);
ctx.stroke();
ctx.restore();
}
function drawMinute(minute,second){
ctx.save();
ctx.beginPath();
var rad = 2*Math.PI/60*minute+(2*Math.PI/60)*(second/60);
ctx.rotate(rad);
ctx.strokeStyle = "#000";
ctx.lineWidth = 5;
ctx.lineCap = "round";
ctx.moveTo(0,15);
ctx.lineTo(0,-(r-40));
ctx.stroke();
ctx.restore();
}
function drawSecond(second){
ctx.save();
ctx.beginPath();
ctx.strokeStyle = "rgb(200, 0, 0)";
var rad = 2*Math.PI/60*second;
ctx.rotate(rad);
ctx.lineWidth = 2;
ctx.lineCap = "round";
ctx.moveTo(0,20);
ctx.lineTo(0,-(r-25));
ctx.stroke();
ctx.restore();
}
function drawCicle(){
ctx.save();
ctx.beginPath();
ctx.fillStyle ="#fff";
ctx.arc(0,0,4,0,Math.PI*2,false);
ctx.fill();
ctx.restore();
}
function timeActive(){
ctx.clearRect(0,0,width,height);
var date = new Date();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
hourspan.innerText = hour;
minutespan.innerText = minute;
secondspan.innerText = second;
drawBackground();
drawHour(hour,minute,second);
drawMinute(minute,second);
drawSecond(second);
drawCicle();
ctx.restore();
}
timeActive();
setInterval(timeActive,1000);
<div class="box">
<span id="hour"></span>:
<span id="minute"></span>:
<span id="second"></span>
</div>
<div>
<canvas id="clock" width="360px" height="360px"></canvas>
*{margin: 0;padding: 0;}
div{
text-align: center;
}
div.box{
margin: 50px auto;
text-align: center;
font-size: 30px;
display: flex;
align-items: center;
justify-content: center;
}
span{
display: inline-block;
font-size: 20px;
margin: 0px 20px;
}
canvas{
transform: scale(.5)
}