Count Down Timer Function

For All those of you that need a Countdown Timer Function: 

function timer() {
 var epoch = Math.round(new Date().getTime() / 1000.0);
 var countDown = 1200 - (epoch % 1200);
 let minutes = (countDown / 60) | 0;
 let seconds = (countDown % 60) | 0;
    minutes = minutes < 10 ? "0" + minutes : minutes;
    seconds = seconds < 10 ? "0" + seconds : seconds;
 if (epoch % 1200 === 0) updateOtp(); // place any other function here
    $w('#textUpdatingIn2').text = minutes + ":" + seconds;
    $w('#updatingIn2').text = minutes + ":" + seconds;
}

This is a very basic Timer and where it says “updateOtp” you can place any function you would like here to take place once your timer has counted down to 0. This timer is set to 1200ms (2 Minutes) but can easily be adjusted. The Countdown is show in a text element here “textUpdatingIn2” and “updatingIn2” I hope this will help someone if it does let me know.

2 Likes

Nice, however @yisrael-wix has already done one for the tutorial section as shown here.
https://www.wix.com/corvid/forum/community-discussion/example-countdown
https://www.velobrewmaster.com/Examples/Countdown
https://www.velobrewmaster.com/Examples/Count-Down-Up

Which can be found on his own page here.
https://www.velobrewmaster.com/examples

Thats Great, I have just had a look, the examples shown I believe do not show how to fire a function, this was just a very basic one that gives the ability for a function to be done after X time.

1 Like

Great this helps me a lot

Is there any way to get this to connect to a progress bar. Something like 87% of the way to Halloween with a progress bar visual

I am sure there will be a way to do so, if you create a function to update the progress bar figure every second, minute or hour or whatever interval you choose to utilise.