Adding embed countdown

Joined
Nov 5, 2022
Messages
1
Reaction score
0
Hello,

I recently found a topic on a different forum showing a live countdown within it, which is pretty cool.

1667659127394.png


Lured by curiosity, I wanted to find the way to do that myself. Most people from already existing topics on different forums kept leading me to the following solution: "Press the Code button while editing the post, then add your code", which does not seem to work properly for me.

I followed each step, like this:

1)
1667658431079.png


2)
1667658470976.png


3) This is what it looks like before posting
1667658537927.png


4) And this is the result
1667658574149.png



There is something I keep doing wrong without noticing, but I did not figure it out yet, although I tried different methods until now. And I cannot ask the author of the original post because he died some time ago, unfortunately, and I found that topic too late. So here I am. What should I adjust in order for my countdown to be displayed correctly?

This is this the website his countdown belongs to: https://www.tickcounter.com/


Thank you in advance for your time spent reading this, as well for your answer(s)!
 
Joined
Sep 12, 2022
Messages
39
Reaction score
0
Hi. Here is an example, try this if it is what you are looking for. Read my inline comments for clarity. I used HTML and js

HTML:
<div id="countdown">
  <span id="days"></span> days
  <span id="hours"></span> hours
  <span id="minutes"></span> minutes
  <span id="seconds"></span> seconds
</div>

JavaScript:
  // Set the date we're counting down to
  var countDownDate = new Date("Jan 5, 2023 15:37:25").getTime();

  // Update the count down every 1 second
  var x = setInterval(function() {

    // Get today's date and time
    var now = new Date().getTime();

    // Find the distance between now and the count down date
    var distance = countDownDate - now;

    // Time calculations for days, hours, minutes and seconds
    var days = Math.floor(distance / (1000 * 60 * 60 * 24));
    var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = Math.floor((distance % (1000 * 60)) / 1000);

    // Output the result in an element with id="countdown"
    document.getElementById("days").innerHTML = days;
    document.getElementById("hours").innerHTML = hours;
    document.getElementById("minutes").innerHTML = minutes;
    document.getElementById("seconds").innerHTML = seconds;

    // If the count down is over, write some text
    if (distance < 0) {
      clearInterval(x);
      document.getElementById("countdown").innerHTML = "Timer has ended";
    }
  }, 1000);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top