JSFiddle - React, Tailwind, and code Playground
HTML
<span id="x"></span>
JavaScript
console.log(new Date().getTime());
var Timer;
var TotalSeconds;
CreateTimer("x",55555);
function CreateTimer(TimerID, Time){
Timer = document.getElementById(TimerID);
TotalSeconds = Time;
window.setTimeout(Tick(), 1000);
}
function Tick() {
alert(TotalSeconds)
TotalSeconds--;
if(TotalSeconds>=0){
UpdateTimer();
window.setTimeout(Tick(), 1000);
}else{
// NO TIME THEN LOGOUT
// alert(SUCCESS_LOGOUT);
}
}
function UpdateTimer() {
var Seconds = TotalSeconds;
var Days = Math.floor(Seconds / 86400);
Seconds -= Days * 86400;
var Hours = Math.floor(Seconds / 3600);
Seconds -= Hours * (3600);
var Minutes = Math.floor(Seconds / 60);
Seconds -= Minutes * (60);
var TimeStr = "" +((Days > 0) ? Days + " days " : "") + LeadingZero(Hours) + ":" + LeadingZero(Minutes) + ":" + LeadingZero(Seconds)+"<b>"
Timer.innerHTML = TimeStr;
}
function LeadingZero(Time) {
return (Time < 10) ? "0" + Time : + Time;
}