View Full Version : Newbie question/PHP Time & Date
Blaze
03-28-2001, 06:01 PM
Hi all. This may be a very simple question, but I have a countdown script and also a simple script to display current date and time. How in each of those cases can I code it so that it's based on a certain time zone, i.e. Eastern. Better yet, would be to append the scripts so that the time is based on where the local user's computer is located. And does PHP allow for automatically refreshing the time/date/countdown versus physically clicking the refresh button on the browser?
I know this is probably an easy question with a simple answer..
STeph
gary_c
04-05-2001, 04:12 AM
If you want to display/use the visitor's local time, why not use javascript instead, since it can get the visitor's system time? Check one of the javascript resource sites for a bunch of scripts for clocks/date/time.
I don't think PHP can dynamically update the time displayed by the browser since PHP functions on the server side. After the page is served, any time functions would depend on the client's system (i.e., using javascript, etc.).
-- gary_c
allen
04-05-2001, 11:53 AM
Hi blaze,
What you want , like gary_c says is javascript. PHP is not a client side scripting agent so after the request has been served, there isn't a way for it to update a clock on the users browser (well, technically there are many ways you could do it with PHP, but the users browser would keep refreshing each second, and why do it the hard way when you can use javascript?).
For javascript, you can do something like this to refresh the users page automatically
<SCRIPT>
var timeout = setTimeout("window.location='thispage.php';",3600);
</SCRIPT>
where thispage.php is the page you want to refresh and 3600 is in seconds.
If you use javascript to tell the date based on the clients system time, then you can just use the getDate(),getMonth(),getHours(),etc.. functions.
eric418
04-27-2001, 11:04 PM
Try this, you don't have to refresh the page at all to get the live moving clock using JavaScript.
Demo
http://leungeric.com/eric/demo/E-Time.htm
Download (E-Time)
http://leungeric.com/eric/creation.php?JavaScript
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.