New Year and Christmas count down script using javascript

Last updated on January 11th, 2022 at 06:12 pm

Click to rate this tutorial!
[Total: 2 Average: 4]

Very simple and powerful count down script using simple javascript for this New Year and Christmas along with the current time showing script as a Christmas Gift.

You can also make use of simple style sheet or change the color inside the html tag <font> to make it look better. Take a look at the code below along with a simple demo.

<html><title> Christmas NewYear CoundDown Script using Javascript</title><center>
<script Language="JavaScript">
//Please dont delete this
//script from Mistonline.in
var timerID = null;
var timerRunning = false;
function stopclock (){
        if(timerRunning)
                clearTimeout(timerID);
        timerRunning = false;
}

function startclock () {
        // Make sure the clock is stopped
        stopclock();
        showtime();
}

function showtime () {
        var now = new Date();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds();

        var date = now.getDate();
        var month = now.getMonth() + 1;
        var year = now.getYear();
        if (year < 1000)
         year+=1900
        
        var timeValue = "" + ((hours < 10 ) ? "0" : "") + hours
        // var timeValue = "" + ((hours >12) ? hours -12 :hours)
        timeValue += ((minutes < 10) ? ":0" : ":") + minutes
        timeValue += ((seconds < 10) ? ":0" : ":") + seconds
        // timeValue += (hours >= 12) ? " P.M." : " A.M."
        
         if (seconds == 0) {
        window.status = "New minute!";
        document.getElementById("time").innerHTML = "New minute!";
         }
        if (minutes == 0 && seconds == 0) {
        window.status = "New hour!";
        document.getElementById("time").innerHTML = "New hour!";
        
         }
        if (hours == 0 && minutes == 0 && seconds == 0) {
        window.status = "Midnight!";
        document.getElementById("time").innerHTML = "Midnight!";
         }

       else if (seconds > 0) {
        document.getElementById("time").innerHTML = timeValue + "  " + date + "/" +  month + "-" + year;        
        window.status = timeValue + "  The Xact time according to your computer clock!     "  + date + "/" + month + "-" + year;
                       }
 
        nextXmas = new Date("December 25, 2000")
        nextXmas.setYear(year)
        msPerDay = 24 * 60 * 60 * 1000 ; // Number of milliseconds per day
        daysLeft = (nextXmas.getTime() - now.getTime()) / msPerDay;
        daysLeft = Math.round(daysLeft);
        document.getElementById("chris").innerHTML =  daysLeft + " days until Christmas Eve!";
        
        nextXmas = new Date("December 31, 2000")
        nextXmas.setYear(year)
        msPerDay = 24 * 60 * 60 * 1000 ; // Number of milliseconds per day
        daysLeft = (nextXmas.getTime() - now.getTime()) / msPerDay;
        daysLeft = Math.round(daysLeft);
        document.getElementById("newyr").innerHTML = daysLeft + " days until New Years Eve!";
                    
        timerID = setTimeout("showtime()",1000);

        timerRunning = true;
}
</script><body onLoad="startclock()">
<center><p><h2>Number of days left for newyear:<font color="red"><div id="newyr"></div></font></h2><br><h2>Number of days left for Christmas:<font color="red"> <div id="chris"></div></font></h2>
<br><h2>The time now is : <font color="red"<div id="time"></div></font><p></h2>

DEMO

Don’t forget to check out our Javascript CountDown Script For Christmas And Newyear Part 2

Click to rate this tutorial!
[Total: 2 Average: 4]

Leave a Reply

Your email address will not be published.