using javascript countdown with server side time

前端 未结 3 1624
没有蜡笔的小新
没有蜡笔的小新 2020-12-16 06:02

I have two scripts one in PHP to get the time server side, and the other is a JavaScript countdown based on a date and time. I am not sure what I am doing wrong, but when I

3条回答
  •  有刺的猬
    2020-12-16 06:29

    I had problems with @Ghostoy's var distance = end - now;

    I noticed my seconds counting down would often pause and skip a number every once in a while. When I displayed the distance, I noticed the milliseconds were shifting a little back and forth.

    For example, as I watched the distance countdown, these were my results:

    400996000
    400995001
    400993998
    400993002
    400991999
    

    Could be just my computer, but if the problem happens on my machine, then it could happen to someone else. As a result, I suggest changing var distance to this:

    var distance = Math.round((end - now)/1000)*1000;
    

    This fixed it on my machine.

提交回复
热议问题