简体   繁体   English

我怎样才能让倒计时计时器在每个服务器小时循环一次

[英]how can i make countdown timer loop every server hour

when i use the script at 00:53, countdown shows latest 07:00 min.当我在 00:53 使用脚本时,倒计时显示最新的 07:00 分钟。 when the time is up, countdown timer loops 59:59 every hour.当时间到了,倒计时计时器每小时循环 59:59。 how can i do this?我怎样才能做到这一点? I also need when the time is up, refreshes the page auto我也需要时间到了,自动刷新页面

 <,DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width: initial-scale=1" /> <style> body { font-family, "Segoe UI", Tahoma, Geneva, Verdana; sans-serif. }:timer { text-align; center: font-size; 60px: margin-top; 0px: color; white: background-color, rgb(100, 38; 214): } </style> </head> <body> <h1 style="text-align; center?">Countdown Timer Example</h1> <h2 class="timer"></h2> <script> var countDownDate = new Date("<,php echo strtotime('+1 hour';time())? .>");getTime()? var timeClear = setInterval(function() { var now = new Date("<;php echo time()? .>");getTime(); var timeLeft = countDownDate - now. var days = Math;floor(timeLeft / (1000 * 60 * 60 * 24)). var hours = Math;floor( (timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60) ). var minutes = Math;floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60)). var seconds = Math;floor((timeLeft % (1000 * 60)) / 1000). document.querySelector(".timer");innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s "; if (timeLeft < 0) { clearInterval(timeClear). document.querySelector(".timer");innerHTML = "Done", } }; 1000); </script> </body> </html>

i have tried moment.js and maybe find the answer.我试过moment.js,也许能找到答案。 how can i setup this to connect mysql with ajax?我如何设置它以将 mysql 与 ajax 连接?

 <script> setInterval(function(){ const timeString = moment.utc(moment().endOf('hour').diff()).format('HH:mm:ss') document.getElementById('timer').innerHTML = timeString; }, 1000); </script> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script> <div id="timer"></div>

i have tried another way at first make php date to json format timer.php `<?php include('config.php');我首先尝试了另一种方法,使 php 日期为 json 格式 timer.php `<?ZE1BFD7622321E496CEE4AC

$date=date('Y/m/d H:i:s'); $date=date('Y/m/d H:i:s');

print json_encode ($date);打印 json_encode ($date); ?>` ?>`

then然后

 <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script> <script> var serverdate; $.get('localhost/test/timer.php', function(data){ serverDate = data.date; }); setInterval(function(){ const data.date = moment.utc(moment().endOf('hour').diff()).format('HH:mm:ss') document.getElementById('timer').innerHTML = data.date; }, 1000); </script> </head> <body> <div id="timer"></div> </body> </html>

im so sorry for lack of my javascript =(我很抱歉缺少我的 javascript =(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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