<UPDATED> You should write your code into a $scalar variable and first have your $REPLACE_WITH..._DATE loaded with your desired date (with the scalar localtime function). See the following one-liner (you can try it, first)...function timeNow() { //Shows the server's time and formats it into hh:mm:ss am/pm f +ormat. now = new Date($REPLACE_WITH_THE_SERVER'S_DATE) ...
Try it several times and you'll see that it changes to your actual date!perl -e'print "Wed Sep 14 23:22:59 EDT 2005\n";my @ti=split(/\s+/,scal +ar localtime);my $year=pop(@ti);push(@ti,"EDT",$year);print join(" ", +@ti),"\n"' Wed Sep 14 23:22:59 EDT 2005 Mon Sep 26 21:01:16 EDT 2005
You could do it better, for sure! But this simply shows how you could have the same format as the one needed for the js new Date() format...
Why using such a horrible and long variable instead of writing the time? Because you are going to run the cgi script every time that a new user calls it. So you should display the actual server's time, and not the old one, Ok?
If you need more acuracy, you should use:scalar localtime(time + $elapsed_seconds), where $elapsed_seconds would have the time that elapsed from the time when the server sends the html page to the time when the user sees it :). (TODO: read about perldoc POSIX and perldoc -f localtime)
NOTICE: All these code intends to start the user's JS clock at the exact time that the user asks the page. If the clock starts at the correct time, it should update every second (depends on the js code, not on the server's code any more) to keep on being correct until the user leaves the page. What happens if the user saves a copy of the html page at his PC? Well, the clock would start again but with the old time, because the server does not display that page again for the user. But there are tricks to do it again, this way, also. Find out more about the "Web Site Story" somewhere where you could find javascript code, it is a rating technique.
In reply to Re: Display clock
by chanio
in thread Display clock
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |