Results 1 to 2 of 2

Thread: Live Date script--can it read time from webserver

  1. #1
    Join Date
    Mar 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Live Date script--can it read time from webserver

    Live Date Script
    http://www.dynamicdrive.com/dynamicindex6/clock3.htm

    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?
    Last edited by mrconwell; 03-11-2005 at 07:44 PM.

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •