Last updated on October 18th, 2022 at 07:51 am

Very simple Javascript that can be easily added to your website.

There are two div’s inside the code as shown above.

	Christmas :-<div id="clock1">[clock1]</div>
	NewYear :-<div id="clock2">[clock2]</div>

All you have to do is change the date and time according to your requirement.Inside the Javascript we are defining two functions for the divs with id clock1 and clock2

StartCountDown("clock1","12/25/2022 00:00 AM")
StartCountDown("clock2","01/01/2023 00:00 AM")

Complete code below

<html>
<head>
<title>Christmas and Newyear CounDown Script From Mistonline.in</title>
</head>
<body><p><h2><center>

	Christmas :-<div id="clock1">[clock1]</div>
	Newyear :-<div id="clock2">[clock2]</div>
</h2></center></body>
<script language="JavaScript">
//Script By Mistonline.in
//Edit the below date value [MM/DD/YY] and TIME according to your convinience.
  StartCountDown("clock1","12/25/2022 00:00 AM")
  StartCountDown("clock2","01/01/2023 00:00 AM")
function StartCountDown(myDiv,myTargetDate)
  {
    var dthen	= new Date(myTargetDate);
    var dnow	= new Date();
    ddiff		= new Date(dthen-dnow);
    gsecs		= Math.floor(ddiff.valueOf()/1000);
    CountBack(myDiv,gsecs);
  }
  
  function Calcage(secs, num1, num2)
  {
    s = ((Math.floor(secs/num1))%num2).toString();
    if (s.length < 2) 
    {	
      s = "0" + s;
    }
    return (s);
  }
  
  function CountBack(myDiv, secs)
  {
    var DisplayStr;
    var DisplayFormat = "%%D%% Days %%H%%:%%M%%:%%S%%";
    DisplayStr = DisplayFormat.replace(/%%D%%/g,	Calcage(secs,86400,100000));
    DisplayStr = DisplayStr.replace(/%%H%%/g,		Calcage(secs,3600,24));
    DisplayStr = DisplayStr.replace(/%%M%%/g,		Calcage(secs,60,60));
    DisplayStr = DisplayStr.replace(/%%S%%/g,		Calcage(secs,1,60));
    if(secs > 0)
    {	
      document.getElementById(myDiv).innerHTML = DisplayStr;
      setTimeout("CountBack('" + myDiv + "'," + (secs-1) + ");", 990);
    }
    else
    {
      document.getElementById(myDiv).innerHTML = "Hurray!!!!!!";
    }
  }

</script><p></html>



DEMO

Don’t forget to check out our Beautiful Christmas Countdown Script

One thought on “Javascript Countdown for Christmas and Newyear”

Leave a Reply

Your email address will not be published. Required fields are marked *