Forum Moderators: coopster

Message Too Old, No Replies

PHP Clock

         

dbarasuk

1:25 am on Dec 22, 2007 (gmt 0)

10+ Year Member



Hello,

The next script outputs the current day of week, month, day of month and then a static time:

The code is:

<?php

echo date('l, F j, Y, H:i:s A ');


?>

today this code would output:
Saturday, December 22, 2007, 02:19:45 and then stops there.

How can i make the seconds increment every time a second goes by, every time a minute is finished, every time an hour is finished.

I suspect this has something to do with looping, how can I do it.?

Second, my website is hosted on an american server; how can I incorporate some code in the codeblock above so that the browser displays the time matching the user computer all still using php and not JAvascript?

Regards,
dbarasuk

jatar_k

1:49 am on Dec 22, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could do it by ip but it wouldn't be exact, you would need to do a little geolocation to figure out the timezone by ip

not sure there is any other way

as far as actively looping it without refreshing, you would be better off doing that with js

eelixduppy

1:01 am on Dec 23, 2007 (gmt 0)



This is definitely a problem that would require javascript for it to work with any smoothness. Refreshing the page would not work very well. I believe you can get the user's timezone offset with javascript. Something like this:

Date().[url=http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Date:getTimezoneOffset]gettimezoneOffset[/url]()

google search 'javascript clock' and you should get a decent amount of results with examples.

mikesmith76

7:05 pm on Dec 23, 2007 (gmt 0)

10+ Year Member



Also just for reference, assuming you are in the uk, you can use the gmdate function to return the current gmt date.

[php.net...]