Im trying to make a JS Clock.. I already done it, the problem is its based on clients local time and everyone have a different time.. it also means that if your pc clock is showing the wrong time, then you will also see that wrong time on web, so I tried to make it based on php function time(); but when I did that, the clock is static, it is not updating each second like it should do. How can I do to make the clock show the time based on my local pc?
This is the code I used to test, it is showing timestamp value because I was testing it but its based on your PC time..
Ignore the comment lines, those are for when I used var currentTime = new Date();.. like this it shows the current time but also based on your pc time..
This is the code I used to test, it is showing timestamp value because I was testing it but its based on your PC time..
Code:
<script type="text/javascript">
function updateClock ( )
{
var currentTime = Math.floor(new Date().getTime() / 1000);
//var currentHours = currentTime.getUTCHours ( );
//var currentMinutes = currentTime.getUTCMinutes ( );
//var currentSeconds = currentTime.getUTCSeconds ( );
//currentHours = ( currentHours < 10 ? "0" : "" ) + currentHours;
//currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
//currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
//var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds;
document.getElementById("clock").firstChild.nodeValue = currentTime;
}
</script>
Ignore the comment lines, those are for when I used var currentTime = new Date();.. like this it shows the current time but also based on your pc time..