我正在研究jQuery,我想在开始时间和结束时间之间进行倒计时。 我有开始时间和结束时间,但也有不同之处,但如何倒计时差异变量时间。我的代码看起来像这样
var receivedTime = $('.external-event').attr('data-receivedtime');
var now = new Date();
var difference = moment.utc(moment(now, "DD/MM/YYYY HH:mm:ss").diff(moment(receivedTime, "DD/MM/YYYY HH:mm:ss"))).format("HH:mm:ss");
我希望这种类型的时间在差异变量:05:47:50
答案 0 :(得分:1)
有关更多jquery倒计时示例,请使用以下链接:
$_SESSION['orders_count']
答案 1 :(得分:0)
但它适用于“05:47”。尝试遵循逻辑并继续......
<body>
<div>Registration closes in <span id="time">05:00</span> minutes!</div>
</body>
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
setInterval(function () {
minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.text(minutes + ":" + seconds);
if (--timer < 0) {
timer = duration;
}
}, 1000);
}
jQuery(function ($) {
var fiveMinutes = 60 * 5,
display = $('#time');
startTimer(fiveMinutes, display);
});
答案 2 :(得分:0)
Java脚本倒计时器[HH:mm:ss]
<head>
<script data-require="jquery@2.1.4" data-semver="2.1.4" src="https://code.jquery.com/jquery-2.1.4.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<div>
<span class="hour">05</span>
: <span class="min">00</span>
: <span class="sec">00</span>
</div>
</body>
</html>
JS
$( document ).ready(function() {
function changeTime(){
var hour = parseInt($(".hour").text());
var min = parseInt($(".min").text());
var sec = parseInt($(".sec").text());
if(hour==0 && min==0 && sec==0){
clearInterval(clock);
timer = false;
}
if(timer){
if(sec==0){
$(".sec").text(59);
if(min==0){
$(".min").text(59);
$(".hour").text(--hour);
}
else
$(".min").text(--min);
}
else{
$(".sec").text(--sec);
}
}
}
var timer = true;
var clock = setInterval(changeTime,1000);
});