简体   繁体   English

15 分钟倒计时器

[英]15-Minute Countdown Timer

I am running a 'just in time' webinar, where the webinar will be shown every '15, '30,' 45 and '60 past the hour.我正在运行一个“及时”网络研讨会,该网络研讨会将在每小时 15 点、30 点、45 点和 60 点显示一次。

I have a countdown timer configured to count down to the next quarter hour, but I also want the text to display something like:我有一个倒数计时器配置为倒计时到下一刻钟,但我也希望文本显示如下内容:

'Next Webinar at 10:15AM' “下一次网络研讨会在上午 10:15”

At the moment, the text always displays the top of the hour time.目前,文本始终显示小时时间的顶部。 Such as 10:00AM or 6:00PM, and doesn't show the 15, 30 or 45 intervals.例如 10:00AM 或 6:00PM,不显示 15、30 或 45 间隔。

My question is: How do I configure the text to display the correct time for the next webinar and how do I configure the countdown to show the countdown until the next quarter hour?我的问题是:如何配置文本以显示下一次网络研讨会的正确时间以及如何配置倒计时以显示下一刻钟的倒计时?

Here is the code:这是代码:

 <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>

Just copy and past the following code只需复制并粘贴以下代码

<!-- 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>

The question is lack of some important details about external scripts you require.问题是缺少有关您需要的外部脚本的一些重要细节。 I guess you use "moment.js" but can't identify the script you use to display the countdown.我猜你使用“moment.js”但无法识别你用来显示倒计时的脚本。

In any case, the code you looking for (to calculate the next start period) is following:无论如何,您要查找的代码(计算下一个开始时间段)如下:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM