Hi, I got this code for https://community.wix.com/velo/forum/coding-with-velo/example-countdown.
I Have been messing with it, but I can’t get it to work. I need the timer to count down to April 2nd at 11:00am. Here is my code:
$w . onReady ( function () {
$w ( '#message' ). text = '' ;
import wixWindow from 'wix-window' ;
$w ( '#group1' ). hide ();
if ( wixWindow . rendering . env === 'browser' || wixWindow . viewMode === 'Preview' ) {
// only when in Front End so we get the user's local time (and not the server time)
// otherwise, the display "flashes" - first the server's rendering, and then the local rendering
let countDownDate = **new** Date ( "Apr 02, 2023 11:00:00" ). getTime ();
let countdown = setInterval ( function () {
let now = **new** Date (). getTime ();
let timeLeft = countDownDate - now ;
let days = Math . floor ( timeLeft / ( 1000 * 60 * 60 * 24 ));
let hours = Math . floor (( timeLeft % ( 1000 * 60 * 60 * 24 )) / ( 1000 * 60 * 60 ));
let minutes = Math . floor (( timeLeft % ( 1000 * 60 * 60 )) / ( 1000 * 60 ));
let seconds = Math . floor (( timeLeft % ( 1000 * 60 )) / 1000 );
$w ( "#days" ). text = "" + days ;
$w ( "#hours" ). text = "" + hours ;
$w ( "#minutes" ). text = "" + minutes ;
$w ( "#seconds" ). text = "" + seconds ;
$w ( '#group1' ). show ();
if ( timeLeft > 0 ) {
$w ( '#message' ). text = "Time left" ;
} **else** {
clearInterval ( countdown );
$w ( '#group1' ). hide ();
$w ( '#message' ). text = "The time has come - See you there!" ;
}
}, 1000 );
}
});