ILYAS415 Posted August 9, 2007 Share Posted August 9, 2007 Okay i got a javascript time which changes to match the time every __ seconds/minutes/hours. However this time depended on the persons computer time. I wanted the script to correspond to the server time so i made these changes... Before: <script> <!-- function show2(){ if (!document.all&&!document.getElementById) return thelement=document.getElementById? document.getElementById("tick2"): document.all.tick2 var Digital=new Date() var hours=Digital.getHours() var minutes=Digital.getMinutes() var seconds=Digital.getSeconds() var dn="PM" if (hours<12) dn="AM" if (hours>12) hours=hours-12 if (hours==0) hours=12 if (minutes<=9) minutes="0"+minutes if (seconds<=9) seconds="0"+seconds var ctime=hours+":"+minutes+":"+seconds+" "+dn thelement.innerHTML="Time: "+ctime+"" setTimeout("show2()",1000) } window.onload=show2 //--> </script> Server time: <script> <!-- function show2(){ if (!document.all&&!document.getElementById) return thelement=document.getElementById? document.getElementById("tick2"): document.all.tick2 var Digital=new Date() var hours=Digital.setHours(<?php echo gmdate("h"); ?>); var minutes=Digital.setMinutes(<?php echo gmdate("i"); ?>); var seconds=Digital.setSeconds(<?php echo gmdate("s"); ?>); var hour=Digital.getHours(); var minute=Digital.getMinutes(); var second=Digital.getSeconds(); var dn="PM" if (hours<12) dn="AM" if (hours>12) hours=hours-12 if (hours==0) hours=12 if (minutes<=9) minutes="0"+minutes if (seconds<=9) seconds="0"+seconds var ctime=hour+":"+minute+":"+second+" "+dn thelement.innerHTML="Time: "+ctime+"" setTimeout("show2()",1000) } window.onload=show2 //--> </script> I have 2 problems, the first one is that:- The server time doesnt change as the user stays on the same page second problem: Lets say the server time is 5am exact. This is how it appears on the site - 5:0:0 I want it to appear as 05:00:00 Please help its urgent. p.s. if u may hav noticed i used php Quote Link to comment Share on other sites More sharing options...
mainewoods Posted August 9, 2007 Share Posted August 9, 2007 var Digital=new Date() var hours=Digital.setHours(<?php echo gmdate("h"); ?>); var minutes=Digital.setMinutes(<?php echo gmdate("i"); ?>); var seconds=Digital.setSeconds(<?php echo gmdate("s"); ?>); you need to take those items out of the function and make global so that they are initalized only once to syncronize the times. <script> <!-- var Digital=new Date() var hours=Digital.setHours(<?php echo gmdate("h"); ?>); var minutes=Digital.setMinutes(<?php echo gmdate("i"); ?>); var seconds=Digital.setSeconds(<?php echo gmdate("s"); ?>); function show2(){ if (!document.all&&!document.getElementById) return // the rest of the code Quote Link to comment Share on other sites More sharing options...
ILYAS415 Posted August 11, 2007 Author Share Posted August 11, 2007 Thanks alot! It worked. This problems been buggin me for a few days Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.