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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Dec 2002
    Location
    Peterborough ON Canada
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Grabbing the current time on the server (not client)??

    Is it possible to use JavaScript to get the current time on the server (not the current Client side time).

    If so, what is the syntax??

    Thank you in advance.
    * Why do people say w w w dot... Why not just say triple-w dot (A Pet Peeve) *

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's not possible in javascript. Can you run a server-side language?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #3
    New to the CF scene
    Join Date
    Dec 2002
    Location
    Peterborough ON Canada
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am pretty sure I can. I can run either PHP or Cold Fusion. I know how to get the current time with Cold Fusion but not how to incorporate it into the script to make the time live (running clock, ticking numbers, etc....).
    * Why do people say w w w dot... Why not just say triple-w dot (A Pet Peeve) *

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your question was though if you could do it with javascript. Brothercake is correct. You probably should ask this in the PHP or Server Side languages forums. There should be someone there that can help. Good Luck.

  • #5
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    I'm pretty sure you can figure it out by using the server's time zone offset (which you can set set statically), the client's time zone offset, and the client's current time.

    Something with getTimezoneOffset() I think.

    Here's an old script I found that should help. No matter what you change your time zone too, it will keep the correct time based on offsets.

    <html>

    <head>
    <script language="javascript" type="text/javascript">
    //borrowed from echoecho
    //http://www.echoecho.com/ubb/viewthread.php?tid=2362&pid=10482&#pid10482
    workDate = new Date()
    UTCDate = new Date()
    UTCDate.setTime(workDate.getTime()+workDate.getTimezoneOffset()*60000)

    function printTime(offset) {
    offset++;
    tempDate = new Date()
    tempDate.setTime(UTCDate.getTime()+3600000*(offset))
    timeValue = ((tempDate.getHours()<10) ? ("0"+tempDate.getHours()) : (""+tempDate.getHours()))
    timeValue += ((tempDate.getMinutes()<10) ? ("0"+tempDate.getMinutes()) : tempDate.getMinutes())
    timeValue += " hrs."
    return timeValue
    }
    var now = new Date()
    var seed = now.getTime() % 0xfffffff
    var same = rand(12)
    </script>

    </head>

    <body>
    Banff, Canada:
    <script language="JavaScript">document.write(printTime("-7"))</script>
    <br>
    Michigan:
    <script language="JavaScript">document.write(printTime("-5"))</script>
    <br>
    Greenwich, England(UTC):
    <script language="JavaScript">document.write(printTime("-0"))</script>
    <br>
    Tokyo, Japan:
    <script language="JavaScript">document.write(printTime("+9"))</script>
    <br>
    Berlin, Germany:
    <script language="JavaScript">document.write(printTime("+1"))</script>

    </body>
    </html>

  • #6
    New Coder
    Join Date
    Jul 2002
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There's a simple SSI directive that can do what you mentioned.

  • #7
    New Coder
    Join Date
    Apr 2003
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    id wrap this up as a custom tag and call it that way, but anyhow here's the CF code you require



    <meta http-equiv="REFRESH" content="150"><HTML><BODY bgcolor=eeeeee><HEAD>
    <cfoutput>
    <cfset tnow=#now()#>
    <cfset snow=#DatePart("s", "#tnow#")#+4>

    <!--- the +4 seconds above is the latency due to internet communications. Typically, this should be set to 3 seconds. About 1 second for internet latency and about 2 seconds to execute the javascript on the first access. We offer a dynamic clock (at extra cost) by monitoring the users latency period and dynamically adjusting the clock time to accomodate latency/CPU.--->

    <script language="JavaScript">
    // 1-----------Javascript developed by LabX.
    // 2-----------Copyright protected
    // 3-----------By Bob Kafato and Fred Plotnikoff info@labx.com
    // 4-----------These four comment lines must be present and unaltered

    function setTime() {
    curhour = "#DatePart("h", "#tnow#")#";
    curminutes = "#DatePart("n", "#tnow#")#";
    curseconds = "#snow#";
    setClock(curhour, curminutes, curseconds);
    }

    function setClock(ch, cm, cs) {
    // -----------this function calculates the new time and tracks it---
    CurHour = parseInt(ch);
    timeHour = CurHour;
    if (CurHour == 24) {
    CurHour = 0;
    timeHour= 0;
    }
    if (CurHour < 10) {
    CurHour = "0" + CurHour;
    }
    CurMinute = parseInt(cm);
    if (parseInt(cm) < 10) {
    CurMinute = "0" + parseInt(cm);
    }
    else CurMinute = parseInt(cm);

    if (parseInt(cs) < 10) {
    CurSeconds = "0" + parseInt(cs);
    }
    else
    CurSeconds = parseInt(cs);

    if (CurHour >= 12) {
    timeHour = CurHour - 12;
    if (timeHour < 10) {
    timeHour = "0" + timeHour;
    Ampm = "pm";
    }
    else
    Ampm = "pm";
    }
    else
    {
    timeHour = CurHour;
    Ampm = "am";
    }

    if (timeHour == 0) {
    timeHour = "12";
    }

    CurMinute = ""+CurMinute;
    CurHour = ""+CurHour;
    Time = timeHour + ":" + CurMinute + ":" + CurSeconds + " " + Ampm;
    document.clocktext.clock.value = Time;
    CurSeconds = parseInt(cs) + 1;
    CurSeconds = ""+CurSeconds;
    CurMinute = parseInt(cm);
    CurHour = parseInt(ch);

    if (parseInt(CurSeconds) > 59) {
    CurMinute = parseInt(cm) + 1;
    CurMinute = ""+CurMinute;
    CurSeconds = 0;
    CurSeconds = parseInt(CurSeconds);
    }

    if (parseInt(CurMinute) == 60) {
    CurHour = parseInt(CurHour) + 1;
    CurMinute = "0";
    CurMinute = parseInt(CurMinute);
    }

    // document.clocktext.clock.value = Time;
    setTimeout ("setClock(CurHour, CurMinute, CurSeconds)", 1000 * 1);
    }

    </script>

    </cfoutput>
    <TITLE>Server Clock</TITLE>
    </HEAD>
    <BODY bgcolor=eeeeee ONLOAD="setTime()">
    <cfoutput>
    <FORM NAME="clocktext">
    <b>
    <font color=000000 face=arial size=2>Server Clock: #DateFormat("#now()#", "mmm dd")#</font>
    <font size=3> &nbsp;<input type="text" name="clock" size="10" value=""></b></FORM></font></cfoutput>
    </body></html>
    Ex <allaire> & Macromedia CF Snr Consultant


  •  

    Posting Permissions

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