0
Can anyone help me with the code?
The timing event for simple offer period like in ecommerce sites.
7 Answers
+ 2
where is the code
+ 1
That's great! Since your profile shows you've completed the JavaScript course, and you've clearly found the Code Playground, go ahead and show us that you've made some effort so we can troubleshoot specific issues instead of guessing what you really want.
0
i want a sample javascript code to activate a timing function
0
oks
0
<html>
<head>
</head>
<body>
<p id="ETA"></p>
<script>
var tool = new Date("January 1, 2019 00:00:00").getTime();
timer = setInterval(
function()
{
var cur = new Date().getTime();
var dist = tool - cur;
var day = Math.floor(dist / (1000 * 60 * 60 * 24));
var minute = Math.floor((dist % (1000 * 60 * 60)) / (1000 * 60));
var hour = Math.floor((dist % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var second = Math.floor((dist % (1000 * 60)) / 1000);
document.getElementById("ETA").innerHTML = day + "d:" + hour + "h:" + minute + "m:" + second + "s";
if(dist < 0)
{
clearInterval(timer);
document.getElementById("ETA").innerHTML = "Ended";
}
}
)
</script>
</body>
</html>
0
i want to improve this to create a proper timing event. reusable.
0
You were able to grab the time just fine. Were you looking for a start / stop mechanism or something?