Make a mechanical clock, clock background, and create an animation effect of three-hand deflection
1. Get the local time
Get the three-hand Object (no details about the style)
var h = document.getElementById("h"); var m = document.getElementById("m"); var s = document.getElementById("s");
Get local time
function setTime(){ var date = new Date();
1)
//思路:设置秒针旋转角度;60 = 360deg; 1 = 6deg; var seceonds = date.getSeconds();//获取当前秒数 s.style.transform=" rotate("+6*senconds+"deg)"; //(style中的样式transform =rotate(x deg))旋转多少度; // 60分钟 = 360deg 1分钟=6deg; var minutes = date.getMinutes(); m.style.transform = "rotate(" + 6 * minutes + "deg)"; //设置时针 //12小时 = 360deg 1小时=30deg var hours = date.getHours(); h.style.transform = "rotate(" + 30 * hours + "deg)"; } setTime();函数调用执行 setInterval(setTime,1000);
The above is the detailed content of How to use js to get the local time as a local pointer. For more information, please follow other related articles on the PHP Chinese website!