Pure Javascript Countdown Timer

Simple Pure JS Countdown Timer

function countdownTimer(seconds) {
    if (seconds <= 0) {
        document.getElementById("countdown-timer").innerHTML = 'Countdown Finish';
    } else {
        seconds = seconds - 1;
        var c_yrs = Math.floor(seconds / (365 * 60 * 60 * 24)) + 0;
        var c_mon = Math.floor((seconds - c_yrs * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24)) + 0;
        var c_day = Math.floor((seconds - c_yrs * 365 * 60 * 60 * 24 - c_mon * 30 * 60 * 60 * 24) / (60 * 60 * 24)) + 0;
        var c_hrs = Math.floor((seconds - c_yrs * 365 * 60 * 60 * 24 - c_mon * 30 * 60 * 60 * 24 - c_day * 60 * 60 * 24) / (60 * 60)) + 0;
        var c_min = Math.floor((seconds - c_yrs * 365 * 60 * 60 * 24 - c_mon * 30 * 60 * 60 * 24 - c_day * 60 * 60 * 24 - c_hrs * 60 * 60) / 60) + 0;
        var c_sec = Math.floor((seconds - c_yrs * 365 * 60 * 60 * 24 - c_mon * 30 * 60 * 60 * 24 - c_day * 60 * 60 * 24 - c_hrs * 60 * 60 - c_min * 60)) + 0;
        document.getElementById("countdown-timer").innerHTML = c_yrs + ' year ' + c_mon + ' month ' + c_day + ' day ' + c_hrs + ' hr ' + c_min + ' min ' + c_sec + ' sec';
        setTimeout("countdownTimer(" + seconds + ")", 999);
    }
}
//var target_date = new Date(year,month,day,hour,minutes,seconds).getTime();
var target_date = new Date(2020, 6, 2, 0, 0, 00).getTime();
var current_date = new Date().getTime();
var seconds_left = (target_date - current_date) / 1000;
countdownTimer(seconds_left);
Pure Javascript Countdown Timer Pure Javascript Countdown Timer Reviewed by Bhaumik Patel on 8:20 PM Rating: 5