# Code countdown tự động lặp lại giúp chốt sale

Vừa rồi khách hàng của mình yêu cầu code countdown tự động lặp lại sau 24h, không cần vào set lại thời gian mà nó sẽ tự động lặp lại thời gian sau khi hết 24h, mình thấy hay quá nên share cho anh em luôn

<figure><img src="/files/TZtIMiKQifN4Cye2JpDJ" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/aI056Y561ZEyekV5gLU5" alt=""><figcaption></figcaption></figure>

```
<!-- code countdown webantam.com share -->
<style>
p#demo {
    text-align: center;
    font-size: 20px;
    margin-top: 0px;
    border-style: none;
    background: #f7cb16;
    border-radius: 10px;
    padding: 20px 20px 20px 20px;
    display: block !important;
    font-weight: normal;
    box-shadow: rgb(0 0 0 / 40%) 0 5px 10px;
}
</style>
<p id="demo"></p>
<script>
function startCountdown() {
  // Set the date we're counting down to
  var countDownDate = new Date();
  countDownDate.setDate(countDownDate.getDate() + 1); // Set the countdown to 24 hours later from now
  countDownDate.setHours(14, 41, 25); // Set the time to 18:39:25

  // 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="demo"
    document.getElementById("demo").innerHTML =  hours + "h "
    + minutes + "m " + seconds + "s ";
      
    // If the count down is over, start a new countdown after 24 hours
    if (distance < 0) {
      clearInterval(x);
      document.getElementById("demo").innerHTML = "EXPIRED";

      // Start a new countdown after 24 hours
      startCountdown();
    }
  }, 1000);
}

// Start the initial countdown
startCountdown();
</script>
```

<figure><img src="/files/qkUxLYczNAxnfjmLGp6o" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learnphp.gitbook.io/learnphp/wordpress-advand/code-countdown-tu-dong-lap-lai-giup-chot-sale.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
