How to fix timer report from time?

  • 0
    There is a timer code that counts up to the date of the event, how to make the timer count exactly the time from the date

    timedown("2020-10-27T07:07:00+02:00","link_1");
    
    function timedown(ti,id){
    
    var countDownDate = new Date(ti).getTime();
    
    var x = setInterval(function() {
    
        var now = new Date().getTime();
        
        var distance = countDownDate - now;
        
        var pad = n=>(n < 10? "0":"") + n;  
        
        var days = Math.floor(distance / (1000 * 60 * 60 * 24));
        var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
        var seconds = Math.floor((distance % (1000 * 60)) / 1000);
    
       document.getElementById(id).innerHTML = "до входа "  + (days!=0 ? days + ":" : "") + pad(hours)+ ":" + pad(minutes) + ":" + pad(seconds);                                                                                       
        if (distance < 0) {
            var x = setInterval(function(){
            clearInterval(x);
           document.getElementById("link_1").innerHTML = "уже проходит " + (days!=0 ? days + ":" : "") + pad(hours) + ":" + pad(minutes) + ":" + pad(seconds);
                }, 1000);
        }
        
    }, 1000);}
    JavaScript Vivian Zhang, Feb 24, 2019

  • 1 Answers
  • 0
    floor rounds down. So a little less than -1 becomes -2. And the seconds can be rounded rather than truncated.

    Well, sculpting another timeout instead of the old one is somehow wrong. You can also fit in one.

    Something like this
    Noah Hendricks

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!