Shahjahan KK
Shahjahan KK

Reputation: 91

Automatic clock for web site

I am trying to put a clock on a website, i am currently getting the time via php built in function. But it does not change the minutes automatically, so that i need to refresh my page.

Is there any technique to put a clock showing time like this [07:23 AM], and update automatically when minute change without refreshing.

Kindly help me out, with code or proper links.

Thanks in Advance.

Upvotes: 2

Views: 5276

Answers (3)

user2334807
user2334807

Reputation:

<script type="text/javascript">

function GetClock(){
d = new Date();
nhour  = d.getHours();
nmin   = d.getMinutes();
nsec   = d.getSeconds();
     if(nhour ==  0) {ap = " AM";nhour = 12;} 
else if(nhour <= 11) {ap = " AM";} 
else if(nhour == 12) {ap = " PM";} 
else if(nhour >= 13) {ap = " PM";nhour -= 12;}

if(nmin <= 9) {nmin = "0" +nmin;}


document.getElementById('clockbox').innerHTML=" "+nhour+":"+nmin+":"+nsec+" "+ap+" ";
setTimeout("GetClock()", 1000);
}
window.onload=GetClock;
</script>
<div id="clockbox"></div>

Here is the full Javascript code that you want. This will work for you.

Upvotes: 4

Ole Aass
Ole Aass

Reputation: 173

You need to use JavaScript's Date() for this if you want to display the current time of the user. If it's the time of the location for the server you want to display you can set a timer that triggers an AJAX call

Upvotes: 0

Alice
Alice

Reputation: 46

jDigiClock

Is a jQuery plugin that has been inspired from the distinctive HTC Hero Clock Widget. For such a complex looking plugin it is surprisingly easy to install and offers

Download it herer and uppload it on your server!

Is this what you ar looking for?

Upvotes: 0

Related Questions