15分钟倒数计时器

时间:2018-03-03 00:20:06

标签: javascript countdown countdowntimer

我正在及时运行'网络研讨会,每次展示网络研讨会,' 30,'过去45小时和60小时。

我有一个倒数计时器配置为倒计时到下一个四分之一小时,但我也希望文本显示如下:

'下次网络研讨会于上午10:15'

目前,文本始终显示小时时间的顶部。例如上午10:00或下午6:00,并且没有显示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>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

问题是缺少有关所需外部脚本的一些重要详细信息。我猜您使用的是“ 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)

答案 1 :(得分:0)

只需复制并粘贴以下代码

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