<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<canvas id="can1" width="500px" height="500px"></canvas>
<script type="text/javascript">
var canvas=document.getElementById(‘can1‘);
var cxt=canvas.getContext(‘2d‘);
function drawClock(){
cxt.clearRect(0,0,500,500);
var date=new Date()
var m=date.getSeconds();
var j=date.getMinutes();
var k=date.getHours();
//表盘
cxt.beginPath();
cxt.strokeStyle="blue";
cxt.lineWidth="10";
cxt.arc(250,250,200,0,360,false);
cxt.stroke();
cxt.closePath();
//表心
cxt.beginPath();
cxt.strokeStyle="#AA1514";
cxt.lineWidth="1";
cxt.arc(250,250,4,0,360,false);
cxt.fill();
cxt.closePath();
//时刻度
for(var i=0;i<12;i++){
cxt.save();
cxt.strokeStyle="black";
cxt.lineWidth="7";
cxt.translate(250,250);
cxt.rotate(30*i*Math.PI/180);
cxt.beginPath();
cxt.moveTo(0,-170);
cxt.lineTo(0,-190);
cxt.closePath();
cxt.stroke();
cxt.restore();
}
//分刻度
for(var i=0;i<60;i++){
cxt.save();
cxt.strokeStyle="black";
cxt.lineWidth="5";
cxt.translate(250,250);
cxt.rotate(6*i*Math.PI/180);
cxt.beginPath();
cxt.moveTo(0,-180);
cxt.lineTo(0,-190);
cxt.closePath();
cxt.stroke();
cxt.restore();
}
//画秒针
cxt.save();
cxt.strokeStyle="black";
cxt.lineWidth="1";
cxt.translate(250,250);
cxt.rotate(6*m*Math.PI/180);
cxt.beginPath();
cxt.arc(0,-130,3,0,360,false);
cxt.fill();
cxt.closePath();
cxt.beginPath();
cxt.moveTo(0,12);
cxt.lineTo(0,-160);
cxt.closePath();
cxt.stroke();
cxt.restore();
//分针
cxt.save();
cxt.strokeStyle="black";
cxt.lineWidth="4";
cxt.translate(250,250);
cxt.rotate(6*j*Math.PI/180);
cxt.beginPath();
cxt.moveTo(0,10);
cxt.lineTo(0,-150);
cxt.closePath();
cxt.stroke();
cxt.restore();
//时针
cxt.save();
cxt.strokeStyle="black";
cxt.lineWidth="6";
cxt.translate(250,250);
cxt.rotate(30*k*Math.PI/180);
cxt.beginPath();
cxt.moveTo(0,8);
cxt.lineTo(0,-140);
cxt.closePath();
cxt.stroke();
cxt.restore();
}
setInterval("drawClock()",1000);
</script>
</body>
</html>