Jump to content

Recommended Posts

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!!!

Link to comment
https://forums.phpfreaks.com/topic/128433-php-time-refresh/
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/128433-php-time-refresh/#findComment-665549
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/128433-php-time-refresh/#findComment-665620
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/128433-php-time-refresh/#findComment-665632
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.