dongshen5115 2015-05-04 13:29
浏览 6
已采纳

PHP / Javascript在2次之间创建倒计时

I currently have many issues trying to think of how to create this script.

I currently have 2 variables :

$curHour = "15:25:00";
$endHour = "16:25:00";

I am struggling to find how to create a countdown specifcally between these times.

I would appreciate any help.

Greetings Glenn

  • 写回答

2条回答 默认 最新

  • duanao4503 2015-05-04 15:01
    关注

    I have just finished in javascript, but the code seems a little long.
    html:

    <div id="process"></div>
    

    javascript:

    var process = document.getElementById('process');
    
    var cur = '15:25:00';
    var end = '16:25:00';
    
    cur = cur.split(':');
    end = end.split(':');
    var x = parseInt(cur[0], 10)*3600+parseInt(cur[1], 10)*60+parseInt(cur[2], 10);
    var y = parseInt(end[0], 10)*3600+parseInt(end[1], 10)*60+parseInt(end[2], 10);
    
    showTime(y);
    var timer = setInterval(function(){
        y--;
        showTime(y);
        if(y<=x){
            clearInterval(timer);
        }
    }, 1000);
    
    function showTime(diff){
        var hour = parseInt(diff/3600, 10);
        var minute = parseInt((diff - hour*3600)/60, 10);
        var second = diff - hour*3600-minute*60;
    
        hour   = hour<10 ? '0'+hour : hour;
        minute = minute<10 ? '0'+minute : minute;
        second = second<10 ? '0'+second : second;
    
        var time = hour+':'+minute+':'+second;
        process.innerHTML = time;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥18 深度学习tensorflow1,ssdv1,coco数据集训练一个模型
  • ¥100 关于注册表摄像头和麦克风的问题
  • ¥30 代码本地运行正常,但是TOMCAT部署时闪退
  • ¥15 关于#python#的问题
  • ¥15 主机可以ping通路由器但是连不上网怎么办
  • ¥15 数据库一张以时间排好序的表中,找出多次相邻的那些行
  • ¥50 关于DynamoRIO处理多线程程序时候的问题
  • ¥15 kubeadm部署k8s出错
  • ¥15 Abaqus打不开cae文件怎么办?
  • ¥15 小程序准备上线,软件开发公司需要提供哪些资料给甲方