Forum Moderators: coopster

Message Too Old, No Replies

Refresh time?

         

Mavicator

8:09 pm on Nov 6, 2004 (gmt 0)

10+ Year Member



I tried using this code to display and refresh the time of day, but obviously it just draws the time over and over on the same line. How do I overwrite the existing time rather than repeat?

<?php
$i=1;
while($i=1)
{
echo date("g:i:s A T");
}
?>

Also is there a way to adjust the time zone? It seems to use the time of my host's server which is EST and I'm on PST. Thanks!

ergophobe

10:46 pm on Nov 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Mavicator,

Welcome to WebmasterWorld!

Unfortunately, I'm not sure I understand your question.

over and over on the same line.

You want it to keep track of previous times and create a list?

How do I overwrite the existing time rather than repeat?

I don't follow that either I'm sorry to say. In terms of the web page, there's really nothing to "overwrite" because by the time that data gets displayed on a page, it's gone from the script.

How about this - give two examples of how you want the date displayed say, on first view and then after refreshing the page.

Cheers,

Tom

Mavicator

11:57 pm on Nov 6, 2004 (gmt 0)

10+ Year Member


Thanks for the reply. I suppose I went into too much detail if anything. All I want to do is display th current date and time on a page. But I was hoping for the "clock" to stay current, i.e. continue counting, not just update when you refresh the page.

The code above doesn't work at all, obviously. It's inserted into a table cell.

mincklerstraat

1:52 am on Nov 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



HTML pages are just output as 'static' pages - i.e., pages with content that doesn't change. If you want the content to change, you need either to have the page refreshed - easiest is:
echo '<META HTTP-EQUIV="Refresh" CONTENT="3;URL='.$_SERVER['PHP_SELF'].'">'; - will refresh after three seconds -

That's probably not what you want though, it will suck your bandwidth, new page every three seconds. A much better way is to use some kind of 'clock' javascript.

Javascript puts code in the user's browser, and the code is run there, independent of your server, and can do all sorts of nifty things (on many webpages, way too many nifty things), including displaying the current time. Try googling javascript clock. You can output the javascript just by escaping out of php (?>Plain Old HTML and Javascript here) or using echo:
echo 'your javascript here';