2

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.

Shahjahan KK
  • 91
  • 1
  • 3
  • 12
  • 1
    use JS ?? or ur only trying it in php ?? If it the case you still need JS/AJAX if you want to do it without page refresh – swapnesh May 01 '13 at 06:41
  • Yea you have to use javascript (jQuery normally) to do client side dynamic events. Try this: http://stackoverflow.com/questions/5507989/javascript-clock-update-on-the-minute-help – Lemon Drop May 01 '13 at 06:43
  • should i use javascript instead of jquery or ajax? – Shahjahan KK May 01 '13 at 06:49

3 Answers3

4
<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.

elembivos
  • 399
  • 2
  • 14
  • Thanks it works, can you plz tell me how to modify it for getting GMT time and adding 5 hr in it? – Shahjahan KK May 01 '13 at 06:52
  • @ShahjahanKK check these links that will help you. http://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript , http://www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/6016329 –  May 01 '13 at 07:04
  • Thank you Dear. That's so nice of you. – Shahjahan KK May 01 '13 at 07:10
0

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?

Alice
  • 46
  • 1
  • 4
0

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

Ole Aass
  • 173
  • 1
  • 4