kokoko Posted July 16, 2011 Share Posted July 16, 2011 *I googled this problem and couldn't find any.. This is the code. What I've changed are only datetimezone and date format. <?php $timezone = new DateTimeZone( "Asia/Seoul" ); $date = new DateTime(); $date->setTimezone( $timezone ); echo $date->format( 'h:i:s A (l, F jS, Y)' ); ?> I mush refresh the page to see the current time. Could anyone tell me how to make this clock ticking without refreshing the page? I want to see every hour, minute, and second ticking. Please help~!! Thank you in advance Quote Link to comment https://forums.phpfreaks.com/topic/242143-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/ Share on other sites More sharing options...
Nodral Posted July 26, 2011 Share Posted July 26, 2011 As php is a serverside, you would need to force the page to refresh to acheive this. A better way is to use either Javascript or ajax. Quote Link to comment https://forums.phpfreaks.com/topic/242143-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/#findComment-1247344 Share on other sites More sharing options...
ZulfadlyAshBurn Posted July 26, 2011 Share Posted July 26, 2011 As php is a serverside, you would need to force the page to refresh to acheive this. A better way is to use either Javascript or ajax. javascript is a good choice. <script type="text/javascript"> <!-- function updateClock ( ) { var currentTime = new Date ( ); var currentHours = currentTime.getHours ( ); var currentMinutes = currentTime.getMinutes ( ); var currentSeconds = currentTime.getSeconds ( ); // Pad the minutes and seconds with leading zeros, if required currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes; currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds; // Choose either "AM" or "PM" as appropriate var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM"; // Convert the hours component to 12-hour format if needed currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours; // Convert an hours component of "0" to "12" currentHours = ( currentHours == 0 ) ? 12 : currentHours; // Compose the string for display var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay; // Update the time display document.getElementById("clock").firstChild.nodeValue = currentTimeString; } // --> </script> <body onload="updateClock(); setInterval('updateClock()', 1000 )"> <span id="clock"> </span> i just modified the code. take note. Quote Link to comment https://forums.phpfreaks.com/topic/242143-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/#findComment-1247359 Share on other sites More sharing options...
Maq Posted July 26, 2011 Share Posted July 26, 2011 Google "javascript time clock", there are plenty of examples & tutorials for you to learn from. Quote Link to comment https://forums.phpfreaks.com/topic/242143-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/#findComment-1247398 Share on other sites More sharing options...
ZulfadlyAshBurn Posted July 26, 2011 Share Posted July 26, 2011 and i just gave one Quote Link to comment https://forums.phpfreaks.com/topic/242143-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/#findComment-1247399 Share on other sites More sharing options...
kokoko Posted July 31, 2011 Author Share Posted July 31, 2011 Thank you for the answers and the script!! But it needs to show the current local time in Seoul, Korea, not the clock on the visitor's desktop. Where and how do I do that? I found only one script but it was wayyyyyyyyy to long to put in. Quote Link to comment https://forums.phpfreaks.com/topic/242143-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/#findComment-1249645 Share on other sites More sharing options...
PFMaBiSmAd Posted July 31, 2011 Share Posted July 31, 2011 http://dynamicdrive.com/dynamicindex6/localtime.htm Quote Link to comment https://forums.phpfreaks.com/topic/242143-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/#findComment-1249646 Share on other sites More sharing options...
kokoko Posted August 1, 2011 Author Share Posted August 1, 2011 WOW!! Thank you for the awesome code! Quote Link to comment https://forums.phpfreaks.com/topic/242143-how-can-i-make-this-clock-ticking-on-my-websitewithout-refreshing-the-page/#findComment-1250112 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.