View Full Version : Live Date script--can it read time from webserver

03-11-2005, 07:40 PM
Live Date Script

I really like the Live Date script that shows the current date and time on my website. However, what I didn't realize what that it reads time directly from my computers internal clock and NOT my webserver! I need the viewers of my website to know what time it is here in order to know when an event takes place. (I live in Indiana so 1/2 the year we are on EST and 1/2 the year we are on CST) Does anyone know how I can edit the script to make it read from my webserver instead of my internal clock?

03-11-2005, 09:04 PM
DHTML/ JavaScript clock scripts cannot access the time on the webserver since they're strictly client side scripts, executed within the visitor's browser. There are DHTML clock scripts that attempt to first get the GMT time then through Math display the time for a specific time zone. A lot of them are inaccuate however, not accounting for Day Light savings time. You can try doing a search on Google for such scripts.

Another technique I just thought of is a lot simplier, though would require your page support a server side language like PHP. Use PHP within the clock script to first get the time on your server and put it in a JavaScript variable, ie:

var servertime="<? php_code_to_get_server_time ?>"

Then get the local time of the visitor using JavaScript, and calculate the difference by substracting the two. The final output of the date script would then be the userstime-difference. Ok, I'm rambling now...