Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Creating Time Variables

    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:
    Code:
    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.
    Last edited by ptmuldoon; 07-17-2007 at 05:30 PM.

  • #2
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

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

    Code:
    var serverhours=servertime.getHours();
    To get the user's local time (as kept by his/her computer) is even simpler:

    Code:
    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.
    - John

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts
    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.

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

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts
    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.

    Code:
    <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>

  • #5
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ptmuldoon View Post
    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.
    - John


  •  

    Posting Permissions

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