You must use this code within
jQuery(document).ready(function(){
jQuery(".promocode").html("20OFF123");
function addMinutes(date, minutes) {
date.setMinutes(date.getMinutes() + minutes);
return date;
}
const date = new Date();
const newDate = addMinutes(date, 5);
//console.log(newDate);
var timeleft = 0;
/*function makeTimer() {
var endTime = newDate;
endTime = (Date.parse(endTime) / 1000);
var now = new Date();
now = (Date.parse(now) / 1000);
timeLeft = endTime - now;
//console.log("time remaining: "+timeLeft)
var days = Math.floor(timeLeft / 86400);
var hours = Math.floor((timeLeft - (days * 86400)) / 3600);
var minutes = Math.floor((timeLeft - (days * 86400) - (hours * 3600 )) / 60);
var seconds = Math.floor((timeLeft - (days * 86400) - (hours * 3600) - (minutes * 60)));
if (hours < "10") { hours = "0" + hours; }
if (minutes < "10") { minutes = "0" + minutes; }
if (seconds < "10") { seconds = "0" + seconds; }
//$("#days").html(days + "
Days");
//$("#hours").html(hours + "
Hours");
jQuery("#minutes").html(minutes + "
Minutes");
jQuery("#seconds").html(seconds + "
Seconds");
if (timeLeft == 0) {
jQuery(".promocode").html("CODE EXPIRED");
//jQuery("#minutes, #seconds").hide();
}
}*/
setInterval(function() { //makeTimer();
var endTime = newDate;
endTime = (Date.parse(endTime) / 1000);
var now = new Date();
now = (Date.parse(now) / 1000);
timeLeft = endTime - now;
//console.log("time remaining: "+timeLeft)
var days = Math.floor(timeLeft / 86400);
var hours = Math.floor((timeLeft - (days * 86400)) / 3600);
var minutes = Math.floor((timeLeft - (days * 86400) - (hours * 3600 )) / 60);
var seconds = Math.floor((timeLeft - (days * 86400) - (hours * 3600) - (minutes * 60)));
if (hours < "10") { hours = "0" + hours; }
if (minutes < "10") { minutes = "0" + minutes; }
if (seconds < "10") { seconds = "0" + seconds; }
//$("#days").html(days + "
Days");
//$("#hours").html(hours + "
Hours");
jQuery("#minutes").html(minutes + "
Minutes");
jQuery("#seconds").html(seconds + "
Seconds");
if (timeLeft == 0) {
jQuery(".promocode").html("CODE EXPIRED");
jQuery("#minutes, #seconds").hide();
clearInterval();
}
}, 1000);
});
.promocode {font-weight:bold; font-size:50px; text-align:center;} #timer {text-align:center; font-size:25px; font-weight:normal;} #minutes, #seconds {color:red; font-weight:bold;}