skip to Main Content

I found this countdown clock in CodePen, but I need to edit it, I need to set the final date to May 30, 2024. ¿Does anybody know how to set up the final date?

document.addEventListener('DOMContentLoaded', () => {

  // Unix timestamp (in seconds) to count down to
  var twoDaysFromNow = (new Date().getTime() / 1000) + (86400 * 2) + 1;

  // Set up FlipDown
  var flipdown = new FlipDown(twoDaysFromNow)

    // Start the countdown
    .start()

    // Do something when the countdown ends
    .ifEnded(() => {
      console.log('The countdown has ended!');
    });

  // Toggle theme
  var interval = setInterval(() => {
    let body = document.body;
    body.classList.toggle('light-theme');
    body.querySelector('#flipdown').classList.toggle('flipdown__theme-dark');
    body.querySelector('#flipdown').classList.toggle('flipdown__theme-light');
  }, 5000);
  
  var ver = document.getElementById('ver');
  ver.innerHTML = flipdown.version;
});

Or anybody can tell me where ¿I can find a flip countdown easy to set up?

THANKS

2

Answers


  1. Get the timestamp with milliseconds of May 30, 2024, then turn it to seconds by dividing by 1000, and pass it to the FlipDown constructor

    const finalDate = new Date('2024-05-30T00:00:00Z').getTime() / 1000;
    
      // Set up FlipDown
    const flipdown = new FlipDown(finalDate)
    
        // Start the countdown
        .start()
    
        // Do something when the countdown ends
        .ifEnded(() => {
          console.log('The countdown has ended!');
        });
    
    Login or Signup to reply.
  2. 86400 * 2 is meant to be 2 days in seconds

    • 24 hours a day
    • 60 minute in the hour
    • 60 second in the minute

    so one day is (24 * 60 * 60 = 86400)
    and 2 days is (2 * 86400)

    review the docs

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search