I'm trying to build an analog clock.
second_hand = document.getElementById('second_hand');
I have a function
that get the time.
function getTime() {
var date = new Date(),
second = date.getSeconds();
return second;
}
Then I have a function
that rotate the hand.
function rotateHand(hand) {
var second = getTime();
hand.style.transformOrigin = "0 100%";
hand.style.transform = 'rotate(' + second * 6 + 'deg)';
}
Then I am using a setInterval
to update my rotateHand()
every second.
setInterval(rotateHand(second_hand), 1000);
But my hand is not updating(moving) every second. What is wrong?
Here is a version of this:
second_hand = document.getElementById('second_hand');
function getTime() {
var date = new Date(),
second = date.getSeconds();
return second;
}
function rotateHand(hand) {
var second = getTime();
hand.style.transformOrigin = "0 100%";
hand.style.transform = 'rotate(' + second * 6 + 'deg)';
}
setInterval(rotateHand(second_hand), 1000);
<div id="second_hand">hiiiiiiiiii</div>