[PHP] OT - Quick JavaScript Question

2003-10-28 Thread Jake McHenry
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? here is the code so far for my javascript 
clock, but it uses the clients time. I either need to replace the Date() function with 
another, or somehow import php's time. I have the time from the server in 
$LogInOutHours:$LogInOutMinutes:$LogInOutSeconds $LogInOutAmPm

Thanks,
Jake


function startclock()
{
  var thetime=new Date();

  var nhours=thetime.getHours();
  var nmins=thetime.getMinutes();
  var nsecn=thetime.getSeconds();
  var AorP= ;

  if (nhours=12) AorP=PM;
  else AorP=AM;

  if (nhours=13) nhours-=12;

  if (nhours==0) nhours=12;

  if (nsecn10) nsecn=0+nsecn;

  if (nmins10) nmins=0+nmins;

  document.timesheet.time.value = nhours+:+nmins+:+nsecn;
  document.timesheet.ampm.value = AorP;

  setTimeout('startclock()',1000);
} 

Re: [PHP] OT - Quick JavaScript Question

2003-10-28 Thread Chris Shiflett
--- Jake McHenry [EMAIL PROTECTED] 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?

Well, that part isn't off-topic, in my opinion.

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

My JavaScript syntax might be wrong, but hopefully you get the idea.

Chris

=
My Blog
 http://shiflett.org/
HTTP Developer's Handbook
 http://httphandbook.org/
RAMP Training Courses
 http://www.nyphp.org/ramp

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] OT - Quick JavaScript Question

2003-10-28 Thread Jake McHenry
- Original Message - 
From: Chris Shiflett [EMAIL PROTECTED]
To: Jake McHenry [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Tuesday, October 28, 2003 2:14 PM
Subject: Re: [PHP] OT - Quick JavaScript Question


 --- Jake McHenry [EMAIL PROTECTED] 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?

 Well, that part isn't off-topic, in my opinion.

 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

 My JavaScript syntax might be wrong, but hopefully you get the idea.

 Chris

 =
 My Blog
  http://shiflett.org/
 HTTP Developer's Handbook
  http://httphandbook.org/
 RAMP Training Courses
  http://www.nyphp.org/ramp

 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


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.

Thanks,
Jake

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] OT - Quick JavaScript Question

2003-10-28 Thread Jordan S. Jones
Jake McHenry wrote:

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.
Thanks,
Jake
 

Yes,
http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/date.html#1193137
Jordan S. Jones

--
I am nothing but a poor boy. Please Donate..
https://www.paypal.com/xclick/business=list%40racistnames.comitem_name=Jordan+S.+Jonesno_note=1tax=0currency_code=USD
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] OT - Quick JavaScript Question

2003-10-28 Thread Eugene Lee
On Tue, Oct 28, 2003 at 02:27:28PM -0500, Jake McHenry wrote:
: Chris Shiflett responded:
:  --- Jake McHenry [EMAIL PROTECTED] 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



Re: [PHP] OT - Quick JavaScript Question

2003-10-28 Thread Jake McHenry
- Original Message - 
From: Eugene Lee [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
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 [EMAIL PROTECTED] 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php