function ShowTime() {
var now = new Date();
var hrs = 19-now.getHours();
var mins = 60-now.getMinutes();
var secs = 60-now.getSeconds();
timeLeft = " " +hrs+' '+mins+' '+secs+' ';
$("#countdown").html(timeLeft);
}
var countdown;
function StopTime() {
clearInterval(countdown);
}
setInterval(ShowTime ,1000);
晚上8:30在这里。我希望如果他到了晚上9点,倒计时再次重启,它会在每天晚上9点重新启动..而且它会变为负值..
答案 0 :(得分:0)
如果您想使用countdown
:
clearInterval
值
countdown = setInterval(ShowTime ,1000);
答案 1 :(得分:0)
请制作这样的逻辑。
If now >19 then
timeLeft is (24-now)+19
else hrs = 19-now;
答案 2 :(得分:0)
function ShowTime() {
var now = new Date();
var hrs;
var currentHours = now.getHours();
if(currentHours>19){
hrs = 24-currentHours+19;
}else{
hrs = 19-now.getHours();
}
var mins = 60-now.getMinutes();
var secs = 60-now.getSeconds();
timeLeft = " " +hrs+' '+mins+' '+secs+' ';
$("#countdown").html(timeLeft);
}