potato_chip Posted October 14, 2008 Share Posted October 14, 2008 I was able to display the current server time on my page, like this: <?php //display today's date, time in top right of each page. $todaydate = date('F j, Y - h:i A'); echo "$todaydate "; ?> This code is in my topmain.php. And topmain.php is included in the index.php. Once the index.php file is loaded, the time displayed is the time when the page was loaded. Does anyone knows how to display the real time as the clock clicks. Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/128433-php-time-refresh/ Share on other sites More sharing options...
ToonMariner Posted October 14, 2008 Share Posted October 14, 2008 javascript... http://www.javascript-page.com/clock.html Quote Link to comment https://forums.phpfreaks.com/topic/128433-php-time-refresh/#findComment-665522 Share on other sites More sharing options...
potato_chip Posted October 14, 2008 Author Share Posted October 14, 2008 Thanks for the quick reply. However, I found this current time was based on the user's computer clock. What I wanted is reading from server time clock, since different user can modify their computer clock. Any suggestion? Quote Link to comment https://forums.phpfreaks.com/topic/128433-php-time-refresh/#findComment-665535 Share on other sites More sharing options...
Shaun Posted October 14, 2008 Share Posted October 14, 2008 You want an php ajax clock. take a look at this: http://ehsun7b.blogspot.com/2007/10/ajax-clock-show-alive-clock-using.html Quote Link to comment https://forums.phpfreaks.com/topic/128433-php-time-refresh/#findComment-665542 Share on other sites More sharing options...
CroNiX Posted October 14, 2008 Share Posted October 14, 2008 I think it is a waste of resources to use ajax to constantly poll the server to return the time. If you have 1000 users doing that, it could easily slow your server down (that would be 60,000 hits a minute on your server)...and for something as trivial as displaying the server time... Why do your users need to know the up-to-the-second server time? If you wanted, you could 1) get server time using php 2) using javascript, you could advance that time so all of the work is done clientside and doesn't waste server resources. Quote Link to comment https://forums.phpfreaks.com/topic/128433-php-time-refresh/#findComment-665549 Share on other sites More sharing options...
Shaun Posted October 14, 2008 Share Posted October 14, 2008 I think it is a waste of resources to use ajax to constantly poll the server to return the time. If you have 1000 users doing that, it could easily slow your server down (that would be 60,000 hits a minute on your server)...and for something as trivial as displaying the server time... Why do your users need to know the up-to-the-second server time? If you wanted, you could 1) get server time using php 2) using javascript, you could advance that time so all of the work is done clientside and doesn't waste server resources. Agreed, use javascript to offset from the servers time Quote Link to comment https://forums.phpfreaks.com/topic/128433-php-time-refresh/#findComment-665620 Share on other sites More sharing options...
potato_chip Posted October 14, 2008 Author Share Posted October 14, 2008 Yes. I want to pass the server time to javascript, and then advance the time. But I don't know how to pass php time() to javascript and process it. here is what I did: var currentTime = <?php echo time(); ?>; But javascript var currentTime = new Date(); But javascript Date() function returns is totally different from php time() does. How can I process the information in javascript? Any help? Pretty new to both languages. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/128433-php-time-refresh/#findComment-665632 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.