Clock on webpage using server and system time?

前端 未结 8 979
无人及你
无人及你 2021-01-02 03:34

I need to add a clock to a web page. The clock needs to be synchronized with a server but I really don\'t want to have it constantly check the server as the page will be ope

8条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 04:23

    You can get the current time from the server on every page load, so even on first load you will have the current server time. After that, you may use a javascript timer on the page set to tick every second, and then you will virtually have a clock working synchronized with the server. You may also try applying offsets as suggested, but i wouldn't recommend since there's lag during postbacks.

    Ajax request might be an interesting option.

    Any doubts, you may also check this clock out!

    Also, W3Schools is a great reference for javascript.

提交回复
热议问题