Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

@adriennetacke
Last activeSeptember 1, 2022 04:18
    • Star(34)You must be signed in to star a gist
    • Fork(5)You must be signed in to fork a gist
    Save adriennetacke/f5a25c304f1b7b4a6fa42db70415bad2 to your computer and use it in GitHub Desktop.
    Countdown timer in pure JavaScript
    functioncountdown(endDate){
    letdays,hours,minutes,seconds;
    endDate=newDate(endDate).getTime();
    if(isNaN(endDate)){
    return;
    }
    setInterval(calculate,1000);
    functioncalculate(){
    letstartDate=newDate().getTime();
    lettimeRemaining=parseInt((endDate-startDate)/1000);
    if(timeRemaining>=0){
    days=parseInt(timeRemaining/86400);
    timeRemaining=(timeRemaining%86400);
    hours=parseInt(timeRemaining/3600);
    timeRemaining=(timeRemaining%3600);
    minutes=parseInt(timeRemaining/60);
    timeRemaining=(timeRemaining%60);
    seconds=parseInt(timeRemaining);
    document.getElementById("days").innerHTML=parseInt(days,10);
    document.getElementById("hours").innerHTML=hours<10 ?"0"+hours :hours;
    document.getElementById("minutes").innerHTML=minutes<10 ?"0"+minutes :minutes;
    document.getElementById("seconds").innerHTML=seconds<10 ?"0"+seconds :seconds;
    }else{
    return;
    }
    }
    }
    (function(){
    countdown('04/01/2333 05:00:00 PM');
    }());
    @oyenmwen
    Copy link

    Thank you so much for this!!! Everything else is too overly complicated :)

    @adriennetacke
    Copy link
    Author

    @oyenmwen, glad it helps! :)

    Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

    [8]ページ先頭

    ©2009-2025 Movatter.jp