[英]15-Minute Countdown Timer
我正在运行一个“及时”网络研讨会,该网络研讨会将在每小时 15 点、30 点、45 点和 60 点显示一次。
我有一个倒数计时器配置为倒计时到下一刻钟,但我也希望文本显示如下内容:
“下一次网络研讨会在上午 10:15”
目前,文本始终显示小时时间的顶部。 例如 10:00AM 或 6:00PM,不显示 15、30 或 45 间隔。
我的问题是:如何配置文本以显示下一次网络研讨会的正确时间以及如何配置倒计时以显示下一刻钟的倒计时?
这是代码:
<script> $(document).on("ready", function(){ // change to todays date: //$(".topHour_date").text( "(TODAY) " + moment().format('dddd MMMM Do') ); $(".topHour_date").text("NEXT CLASS TODAY "); // change next house $(".topHour_time").text( moment().add(0.1, 'hour').startOf('hour').format('h:mm A')); $time_now = moment().format("mm"); $time_now_difference = 15 - $time_now; $time_now_diff_seconds = $time_now_difference * 60; $.countdown.setDefaults($.countdown.regionalOptions["eng"]); $(".elCountdownEvergreen").countdown({ until: $time_now_diff_seconds, padZeroes: true }); }); </script>
只需复制并粘贴以下代码
<!-- Display the countdown timer in an element -->
<p id="demo"></p>
<script>
// Set the date we're counting down to
var countDownDate = new Date().getTime() + 15 * 60 * 1000;
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
// Time calculations for hours, minutes and seconds
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id="demo"
document.getElementById("demo").innerHTML = hours + ":"
+ minutes + ":" + seconds;
// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
</script>
问题是缺少有关您需要的外部脚本的一些重要细节。 我猜你使用“moment.js”但无法识别你用来显示倒计时的脚本。
无论如何,您要查找的代码(计算下一个开始时间段)如下:
var next = new Date(); // now
next.setTime(next.getTime() + 15 * 60 * 1000) // add 15 minutes
next.setMinutes(15 * Math.floor(next.getMinutes() / 15)) // rounding to the start of quarter or hour
next.setSeconds(0) // the period starts in 00 seconds of minute.
// format the output
next = moment(next).format('h:mm A')
// ... and display the next quarter of hour with
$('#some_output_div').text(next)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.