如何解决带有开始和结束时间的Javascript数倒计时不是计时器
我发现有很多倒计时计时器,它们可以从特定日期/时间倒数到特定日期/时间,但是我需要一个脚本来倒数(而不是时间)-在指定日期内从300减少到1 /时间范围。 例如,倒数计时需要每天从8.00am在每天8.00开始,并全天递减直到直到8.00pm在1结束。 这是我找到的最接近的[https://codepen.io/petyoyo/pen/aVggJz][1],但可以在几秒钟内使用。不幸的是,我对JavaScript知之甚少,无法对其进行调整。谁能帮忙-有可能吗?
// Set the date we're counting down to
var countDownDate = new Date("Dec 11,2017 19:49:00").getTime(); //CHANGE HERE<----
// Update the count down every 1 second
var x = setInterval(function() {
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now an the count down date
var distance = countDownDate - now;
// Time calculations for days,hours,minutes and seconds
var seconds = Math.floor((distance % (1000 * 60))/1000 ) + //seconds
(Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)))*60 + 340000 + // min to sec
(Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)))*60*60+ // hours to sec
(Math.floor(distance / (1000 * 60 * 60 * 24)))*60*60*60; // days to sec
// Display the result in the element with id="demo"
document.getElementById("demo").innerHTML = seconds;
// If the count down is finished,write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
},1000);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。