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

图片转代码服务由CSDN问答提供 功能建议

我目前在尝试思考如何创建此脚本时遇到很多问题。 < p>我目前有2个变量:

  $ curHour =“15:25:00”; 
 $ endHour =“16:25:00”; 
   
 
 

我很难找到如何在这些时间之间专门创建倒计时。

我将不胜感激任何帮助。 \ n

问候格伦

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

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条)

相关推荐 更多相似问题