Search code examples
javascripttimeactioncallntp

Call function when server time is reached


I'm not as well practiced in JavaScript programming. At least I think it has been. Therefore, I again condemn the question to you. Possibly ye have indeed a working script or a good howto. I would like to be on one side of an action to perform a very specific time.

As n Example: On a site there is nothing to see except some text, a few pictures. So a normal website. At 19:45 clock to be automatically linked to another page. That's all really. Something like a timer (after x seconds do action) I do not mean. A fixed time is important. It would be also important the time comes from the server and from the client. Possibly this can indeed pick from the same server or by an official NTP server.

Have you an idea?

Would be great and a really big help. Will surprise someone.

Thank you very much in advance.


Solution

  • i have tried my best. Here my Script

    <script type="text/javascript">
       var now = new Date();
       var calMillisecs = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 17, 57, 0, 0) - now;
    
       if (calMillisecs < 0) {
          calMillisecs += 86400000;
       }
    
       setTimeout(function(){alert("Uhrzeit Erreicht !")}, calMillisecs);
    </script>
    

    Works great.

    But any Ideas how i can use an official NTP Server and not the client time ? I tried it with this http://jehiah.cz/a/ntp-for-javascript But without success.

    Any ideas ?