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.
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.
Share Improve this question asked May 1, 2013 at 6:40 Shahjahan KKShahjahan KK 911 gold badge3 silver badges12 bronze badges 3- 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 Commented May 1, 2013 at 6:41
- Yea you have to use javascript (jQuery normally) to do client side dynamic events. Try this: stackoverflow./questions/5507989/… – Lemon Drop Commented May 1, 2013 at 6:43
- should i use javascript instead of jquery or ajax? – Shahjahan KK Commented May 1, 2013 at 6:49
3 Answers
Reset to default 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.
jDigiClock
Is a jQuery plugin that has been inspired from the distinctive HTC Hero Clock Widget. For such a plex 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?
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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745387780a4625516.html
评论列表(0条)