how to make javascript to only count the second? -
i have found following script online useful countdown time, want count seconds, e.g count 86400 seconds instead of 10days. if divide 60 @ first one, calculate seconds correctly, , show number, however, static , not moving since second should change every second.how can achieve that? don't understand why divide 1000 @ beginning either because don't know current_date format. appreciate helps.
// set date we're counting down var target_date = new date("jul 10, 2016").gettime(); // variables time units var days, hours, minutes, seconds; // tag element var countdown = document.getelementbyid("countdown"); // update tag id "countdown" every 1 second setinterval(function () { // find amount of "seconds" between , target var current_date = new date().gettime(); var seconds_left = (target_date - current_date) / 1000; // format countdown string + set tag value countdown.innerhtml = seconds_left + "s"; }, 1000);
<div id="countdown"></div>
try this:
// set date we're counting down var target_date = new date("aug 15, 2019").gettime(); // variables time units var days, hours, minutes, seconds; // tag element var countdown = document.getelementbyid("countdown"); // update tag id "countdown" every 1 second setinterval(function () { // find amount of "seconds" between , target var current_date = new date().gettime(); var seconds_left = (target_date - current_date) / 1000; // format countdown string + set tag value countdown.innerhtml = seconds_left + "s"; }, 1000);
function gettime() returns milisecond, therfore divided 1000 seconds.
Comments
Post a Comment