Re: OT - Quick JavaScript Question

From: Date: Tue, 28 Oct 2003 20:33:48 +0000
Subject: Re: OT - Quick JavaScript Question
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-167934@lists.php.net to get a copy of this message
----- Original Message ----- From: "Eugene Lee" <list-php-1@fsck.net> To: <php-general@lists.php.net> Sent: Tuesday, October 28, 2003 2:45 PM Subject: Re: [PHP] OT - Quick JavaScript Question > On Tue, Oct 28, 2003 at 02:27:28PM -0500, Jake McHenry wrote: > : "Chris Shiflett" responded: > : > --- Jake McHenry <linux@nittanytravel.com> wrote: > : > > > : > > I know this is a bit off topic, but does anyone know of a way I > : > > can take the server time in php and get it into javascript? > : > > : > JavaScript and HTML are the exact same thing from the perspective of > : > PHP; they're output. So yes, you can get any information from PHP to > : > JavaScript by writing it: > : > > : > <script language="javascript"> > : > ... > : > <? > : > $ts = time(); > : > echo "var ts = $ts;\n"; > : > ?> > : > ... > : > </script> > : > : I have tried this already, and it works, the JavaScript get's the server's > : time, but then the JavaScript clock doesn't keep counting, it's stuck at the > : servers time. It needs that Date() function to keep pulling the time from > : the local machine I guess. I was wondering if anyone knew of a way I could > : pass the server time into the JavaScript Date() function to make it start > : counting from that time, instead of the users machine time. > > That's because you're only giving it a static time and not a real > JavaScript Date() object. Try this: > > <script language="javascript"> > ... > var ts = new Date(<?php echo time(); ?>); > ... > </script> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > This doesn't work either. 1) the time now is 5 minutes fast compared to what it actually is on the server. 2) it still is not counting, it's stuck at the wrong time. Any other ideas? The date/time on the system is correct. I tried echoing the time() in php, and get this, 1067373085. Thanks, Jake

« previous php.general (#167934) next »