CountdownTutorials

Date Time Countdown Timer

Date Time Countdown Timer

Date Time Countdown Timer

Before We Start

Date Time Countdown Timer. Websites have timers which show the accurate time that can be used for any special event and coming soon things by using a countdown.

If there is a countdown in a website, it takes more attention and it highlights to the users the exact time the event is on and gives them a better experience.It has the remaining dates so the users can get a perfect idea than showing just the date.

Date Time Countdown Timer. So if you are a person who wishes to develop a website, it will be so wonderful if you know how to create a countdown too. Do you know how to create a countdown perfectly?

We are here to solve your problem.

However in this article you are going to learn, how to develop a countdown completely.

Before we start please read the below articles which easier you to understand the process, if you are new to development.

Step 1 – Add HTML

It’s too easy and simple. Just copy and paste below code in your HTML editor between <body> </body> tag.

<body>
<div id="timer" style="padding-top: 100px;"></div>
</body>

Step 2 – Add CSS

Copy and paste below code in your HTML editor between <style></style> tag.

<style>
body {
  text-align: center;
  padding: 70px 50px;
  background: #0d1a29;
  font-family: sans-serif;
  font-weight: lighter;
}

#timer {
  font-size: 3em;
  font-weight: 100;
  color: white;
  text-shadow: 0 0 20px #48c8ff;
}

#timer div {
  display: inline-block;
  min-width: 90px;
}

#timer div span {
  color: #b1cdf1;
  display: block;
  font-size: 0.35em;
  font-weight: 400;
}

</style>

Step 2 – Add JavaScript

Copy and paste below code in your HTML editor between <script></script> tag.

<script>
function updateTimer() {
  future = Date.parse("dec 2, 2020 11:30:00");
  now = new Date();
  diff = future - now;

  days = Math.floor(diff / (1000 * 60 * 60 * 24));
  hours = Math.floor(diff / (1000 * 60 * 60));
  mins = Math.floor(diff / (1000 * 60));
  secs = Math.floor(diff / 1000);

  d = days;
  h = hours - days * 24;
  m = mins - hours * 60;
  s = secs - mins * 60;

  document.getElementById("timer").innerHTML =
    "<div>" +
    d +
    "<span>days</span></div>" +
    "<div>" +
    h +
    "<span>hours</span></div>" +
    "<div>" +
    m +
    "<span>minutes</span></div>" +
    "<div>" +
    s +
    "<span>seconds</span></div>";
}
setInterval("updateTimer()", 1000);
</script>

Date Time Countdown Timer

At the end we will have something like this. You can change fonts, colors, backgrounds and all things that you want.Enjoy it.

Date Time Countdown Timer

Video Tutorial

Please watch this video to better understand this tutorial and don’t forget to subscribe to our channel.


More articles

https://w3schoolweb.com/how-to-create-image-gallery-in-html/

https://w3schoolweb.com/how-to-create-simple-image-slider/

https://w3schoolweb.com/how-to-create-simple-image-gallery/

https://w3schoolweb.com/how-to-create-bootstrap-gallery/


Help others to find out about this article on Social Media sites. If you have any doubt or any problem, don’t hesitate to contact us. Thereafter we will be able to help you and also make sure you bookmark our site on your browser.

Related Articles

Leave a Reply

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

Back to top button