...

View Full Version : Creating Time Variables



ptmuldoon
07-17-2007, 05:11 PM
I'm very new to javascript, sticking mainly with php, but I could use some help with this problem.

I have a flash object count down clock, that uses the following:

value="server={NOW}&localtime={LOCALNOW}

I need to somehow put the server time and localtime into a javascript to use with the above. The variables should be in Unix time. Does that some sense? I'm starting to google out some javascript time examples, but haven't quite gotten it figured out yet. I think its probably alot simpler than I'm making it out to be.

jscheuer1
07-17-2007, 06:08 PM
This will get a PHP server's time into a javascript date variable. You can get day, date, month, hours, minutes, seconds, and/or year from it using the various javascript Date methods for those:


var servertime=new Date('<?php print date("F d, Y H:i:s", time())?>');

Example for getting the hours:


var serverhours=servertime.getHours();

To get the user's local time (as kept by his/her computer) is even simpler:


var usertime=new Date();

You can also get the various values mentioned above from this new date variable.

See:

http://www.w3schools.com/jsref/jsref_obj_date.asp

If you need to get a local time for a specific location and you know the time zone used by the server and the time zone used by that location, that can also be done, but it isn't clear if that is what you are going for.

ptmuldoon
07-17-2007, 07:28 PM
Thanks for the help, and I understand the code you posted, and may be making some progress. I think part of my issue here is the below initial code is using php variables, when I would need to change them to use javascript variable. Does that even make sense? So after getting the server time and local time in to a javascript variable, I need to get it into the below code.


value="server={NOW}&amp;localtime={LOCALNOW}

ptmuldoon
07-17-2007, 09:06 PM
Ok, As I continue trying to figure this one out on my own, I thought i would post the entire piece of small code of my issue.

As you can see below, I am embedding a flash object (countdown clock), and clock is to countdown to the 'target' time.

I'm not certain, but the existing {NOW} and {LOCALNOW} variables appear to be php variables. My goal is to somehow change the variables to be obtained with javascript instead.



<object type="application/x-shockwave-flash" data="draft_clock.swf" width="300" height="100">
<param name="movie" value="draft_clock3.swf"/>
<param name="flashvars" value="server={NOW}&amp;localtime={LOCALNOW}&amp;target=1188745200000"/>
</object>

jscheuer1
07-18-2007, 08:13 AM
I'm not certain, but the existing {NOW} and {LOCALNOW} variables appear to be php variables. My goal is to somehow change the variables to be obtained with javascript instead.

It would be a big step forward if you could determine if they really are PHP variables or not. Also, I can't see how obtaining them with javascript could be your goal. Perhaps you think it is a step along the way to your goal. More likely, from what you've told me, your goal is to display a flash object. But, to really help, I need to know what they are and what you are really trying to do.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum