Setting Date Time

Discussion in 'ASP General' started by Harag, Dec 20, 2003.

  1. Harag

    Harag Guest

    Hi all


    I think this is in the wrong group but since I don't read others much
    or code in java script I was wondering if anyone could help me with
    this small problem, as I code mostly in ASP vbscript.

    I have the following piece of Javascript client code that displays the
    users clock on the browser and updates it every second.

    I was wondering is it possible for me to set the time to the SERVER
    time via ASP vbscript. and then update this time every second on the
    users browser. I want all users to see the time & date of the SERVER
    and not thier time/date. I've tried looking at
    www.javascriptsource.com and not found anything that might help.

    The current code I have is:

    function NewTime() {
    mDateTime1 = Date().split(" ");
    var clockHandle = true; // Dummy init value
    clockHandle = GetElement('MyDateTime');
    if (clockHandle) {
    clockHandle.innerHTML = mDateTime1[1] + " " +
    mDateTime1[2] + ", " + mDateTime1[4] + ", " + mDateTime1[3];
    }
    setTimeout("NewTime()",500);
    }

    Could anyone modify this so I can set the time for it to start at???

    Thanks for any help on this matter.

    Al.
     
    Harag, Dec 20, 2003
    #1
    1. Advertising

  2. Harag

    Ray at Guest

    If you want to get the server's time, just use <%=Time%> wherever you need
    it to appear. You can put <%=Time%> in your jscript code if that's where
    you need it.

    Ray at home

    "Harag" <> wrote in message
    news:...
    > Hi all
    >
    >
    > I think this is in the wrong group but since I don't read others much
    > or code in java script I was wondering if anyone could help me with
    > this small problem, as I code mostly in ASP vbscript.
    >
    > I have the following piece of Javascript client code that displays the
    > users clock on the browser and updates it every second.
    >
    > I was wondering is it possible for me to set the time to the SERVER
    > time via ASP vbscript. and then update this time every second on the
    > users browser. I want all users to see the time & date of the SERVER
    > and not thier time/date. I've tried looking at
    > www.javascriptsource.com and not found anything that might help.
    >
    > The current code I have is:
    >
    > function NewTime() {
    > mDateTime1 = Date().split(" ");
    > var clockHandle = true; // Dummy init value
    > clockHandle = GetElement('MyDateTime');
    > if (clockHandle) {
    > clockHandle.innerHTML = mDateTime1[1] + " " +
    > mDateTime1[2] + ", " + mDateTime1[4] + ", " + mDateTime1[3];
    > }
    > setTimeout("NewTime()",500);
    > }
    >
    > Could anyone modify this so I can set the time for it to start at???
    >
    > Thanks for any help on this matter.
    >
    > Al.
     
    Ray at, Dec 20, 2003
    #2
    1. Advertising

  3. Harag

    Evertjan. Guest

    Harag wrote on 20 dec 2003 in microsoft.public.inetserver.asp.general:
    > I think this is in the wrong group but since I don't read others much
    > or code in java script I was wondering if anyone could help me with
    > this small problem, as I code mostly in ASP vbscript.
    >
    > I have the following piece of Javascript client code that displays the
    > users clock on the browser and updates it every second.
    >


    Only coded for IE:

    ======== times.asp =======

    Client timezone corrected server date/time:
    <div id=a>Please wait</div>
    Client date/time:
    <div id=b>Please wait</div>

    <script runat=server language=jscript>
    gmt=+new Date()
    </script>

    <script>
    var t=+<%=gmt%>
    var tOut
    function eachSecond(){
    tOut=setTimeout('eachSecond()',1000)
    a.innerHTML=new Date(t)
    b.innerHTML=new Date()
    t+=1000
    }
    eachSecond()
    </script>

    ================

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Dec 20, 2003
    #3
  4. Harag

    Don Verhagen Guest

    "Harag" <> wrote in message
    news:...
    > Hi all
    >
    >
    > I think this is in the wrong group but since I don't read others much
    > or code in java script I was wondering if anyone could help me with
    > this small problem, as I code mostly in ASP vbscript.
    >
    > I have the following piece of Javascript client code that displays the
    > users clock on the browser and updates it every second.

    [remaining post snipped]

    I never understood the purpose of putting the users's clock on a webpage. It
    always seems like a waste of resources, especially updating every second.
    The user already has a clock, why give them another?

    Don
     
    Don Verhagen, Dec 20, 2003
    #4
  5. Harag

    Harag Guest

    Hi

    THANKS! for the help, it works great.

    I've copied my version below incase anyone is interested.

    Al

    *********************
    <%@ language="VBScript" %>
    <% Option Explicit %>
    <%
    ' VBscript!!!
    DIM GMT
    GMT = year(now) & ", "&month(Now)-1&", "&day(now)&",
    "&hour(now)&", "&Minute(Now)&", " & second(now)
    %>

    <head>
    <script language="JavaScript1.2" type="text/javascript">
    <!-- Begin
    function UserTime()
    {
    mDateTime1 = Date().split(" ");
    var clockHandle = true; // Dummy init value
    clockHandle = GetElement('MyDateTime');
    if (clockHandle) {
    clockHandle.innerHTML = mDateTime1[1] + " " +
    mDateTime1[2] + ", " + mDateTime1[4] + ", " + mDateTime1[3];
    }
    setTimeout("UserTime()", 500);
    }


    var t=+ new Date(<%=GMT %>)
    function ServerTime() {
    mServerDT = new Date(t)
    monthNames = new Array("", "Jan", "Feb", "Mar", "April",
    "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec")
    Hour = mServerDT.getHours()
    Minutes = mServerDT.getMinutes()
    Seconds = mServerDT.getSeconds()
    Day = mServerDT.getDate()

    Hour < 10 ? Hour = "0" + Hour.toString() :
    Hour=Hour.toString()
    Minutes < 10 ? Minutes = "0" + Minutes.toString() :
    Minutes=Minutes.toString()
    Seconds < 10 ? Seconds = "0" + Seconds.toString() :
    Seconds=Seconds.toString()
    Day < 10 ? Day = "0" + Day.toString() : Day=Day.toString()

    var clockHandle = true; // Dummy init value
    clockHandle = GetElement('ServerDateTime');
    if (clockHandle) {
    clockHandle.innerHTML = Hour + ":" + Minutes + ":" +
    Seconds + " " + monthNames[mServerDT.getMonth()+1] + " " + Day + ", "
    + (mServerDT.getFullYear()+21)
    }
    t +=500
    setTimeout('ServerTime()', 500)
    }
    // End -->
    </script>
    </head>

    ===========================
    GetElement.js included as well:

    var DOM = (document.getElementById ? 1 : 0);
    var IE4DOM = (document.all ? 1 : 0);

    function GetElement(id) {
    var idHandle = (DOM ? document.getElementById(id) : (IE4DOM ?
    document.all[id] : false));
    return (idHandle ? idHandle : false);
    }


    On 20 Dec 2003 08:18:49 GMT, "Evertjan."
    <> wrote:

    >Harag wrote on 20 dec 2003 in microsoft.public.inetserver.asp.general:
    >> I think this is in the wrong group but since I don't read others much
    >> or code in java script I was wondering if anyone could help me with
    >> this small problem, as I code mostly in ASP vbscript.
    >>
    >> I have the following piece of Javascript client code that displays the
    >> users clock on the browser and updates it every second.
    >>

    >
    >Only coded for IE:
    >
    >======== times.asp =======
    >
    >Client timezone corrected server date/time:
    ><div id=a>Please wait</div>
    >Client date/time:
    ><div id=b>Please wait</div>
    >
    ><script runat=server language=jscript>
    > gmt=+new Date()
    ></script>
    >
    ><script>
    > var t=+<%=gmt%>
    > var tOut
    > function eachSecond(){
    > tOut=setTimeout('eachSecond()',1000)
    > a.innerHTML=new Date(t)
    > b.innerHTML=new Date()
    > t+=1000
    > }
    > eachSecond()
    ></script>
    >
    >================
     
    Harag, Dec 20, 2003
    #5
  6. Harag

    Evertjan. Guest

    Harag wrote on 20 dec 2003 in microsoft.public.inetserver.asp.general:
    > <%
    > ' VBscript!!!
    > DIM GMT
    > GMT = year(now) & ", "&month(Now)-1&", "&day(now)&",
    > "&hour(now)&", "&Minute(Now)&", " & second(now)
    > %>


    The problem you make is that serverside vbs "Now" is server local time and
    not necessarily GMT or the local time of the client.

    Except when server and all clients are in the same timezone, including
    summertime definition, this seems an unrealistic approach.

    Serverside jscript can as shown be manipulated to show UT = GMT.
    Clientside javascript can change this to client local time.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Dec 20, 2003
    #6
  7. Harag

    Harag Guest

    Hi

    Yes, this is exactly the time I wanted showing on all clients
    machines... the server time.

    I'm helping in doing a small multi-player browser game where the
    server time is more important to the client than any other time as the
    players will do orders that relate to the server time. I just thought
    it would be nice to have the clock "ticking" rather than a static
    update everytime they refreshed the pages.

    Thanks again.

    Al.



    On 20 Dec 2003 18:49:30 GMT, "Evertjan."
    <> wrote:

    >The problem you make is that serverside vbs "Now" is server local time and
    >not necessarily GMT or the local time of the client.
     
    Harag, Dec 22, 2003
    #7
  8. Harag

    Harag Guest

    I couldn't agree more... :)

    The clock I want to actual display is the SERVERS time.

    Al.

    On Sat, 20 Dec 2003 10:42:36 -0500, "Don Verhagen"
    <> wrote:

    >
    >"Harag" <> wrote in message
    >news:...
    >> Hi all
    >>
    >>
    >> I think this is in the wrong group but since I don't read others much
    >> or code in java script I was wondering if anyone could help me with
    >> this small problem, as I code mostly in ASP vbscript.
    >>
    >> I have the following piece of Javascript client code that displays the
    >> users clock on the browser and updates it every second.

    >[remaining post snipped]
    >
    >I never understood the purpose of putting the users's clock on a webpage. It
    >always seems like a waste of resources, especially updating every second.
    >The user already has a clock, why give them another?
    >
    >Don
    >
    >
     
    Harag, Dec 22, 2003
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Buchan
    Replies:
    2
    Views:
    740
    Kevin Buchan
    Dec 1, 2003
  2. Chris Berg
    Replies:
    0
    Views:
    829
    Chris Berg
    Oct 27, 2003
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,332
    Michael Borgwardt
    May 30, 2004
  4. Keith Cochrane
    Replies:
    2
    Views:
    635
    Keith Cochrane
    Aug 6, 2006
  5. Summu82
    Replies:
    5
    Views:
    890
    Richard Heathfield
    Jun 7, 2006
Loading...

Share This Page