倒计时N秒

简介: 倒计时N秒
<html>
<head>
<meta charset="UTF-8">
<title>1分钟倒计时</title>
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>
<div id="livetime" style="color: black;"></div>
</body>
<script type="text/javascript"> 
var timestart = 60;//时间;
var timestep = -1;
var timeID;
function timecount() {
  $("#livetime").html(formatSeconds(timestart));
    timestart += timestep;
    if(timestart < 0){
      timestart = 60;//时间;//赋值0  倒计时结束,就变00:00
    return false;
      //倒计时为0时执行xxxx方法   
    }
    timeID=setTimeout("timecount()",1000);
}
formatSeconds = function(timestart) { 
  var theTime = parseInt(timestart);// 需要转换的时间秒 
  var theTime1 = 0;// 分 
  var theTime2 = 0;// 小时 
  var theTime3 = 0;// 天
  if(theTime >= 60) { 
    theTime1 = parseInt(theTime/60); 
    theTime = parseInt(theTime%60); 
    if(theTime1 > 60) { 
      theTime2 = parseInt(theTime1/60); 
      theTime1 = parseInt(theTime1%60); 
      if(theTime2 > 24){
        //大于24小时
        theTime3 = parseInt(theTime2/24);
        theTime2 = parseInt(theTime2%24);
      }
    } 
  } else {
    var result = '00:';
    if(theTime < 10) {
      result += '0'+theTime;
    } else {
      result += theTime;
    }
    return result;
  }
  var result = '';
  if(theTime > 0){ // 秒
    theTime = parseInt(theTime);
    if(theTime < 10) {
      theTime = '0'+theTime;
    }
    result = ""+theTime;
  } else {
    result += "00";
  }
  if(theTime1 > 0) { // 分钟
    theTime1 = parseInt(theTime1);
    if(theTime1 < 10) {
      theTime1 = '0'+theTime1;
    } 
    result = ""+theTime1+":"+result; 
  } else {
    result += "00";
  }
  if(theTime2 > 0) { // 小时
    theTime2 = parseInt(theTime2);
    if(theTime2 < 10) {
      theTime2 = '0'+theTime2;
    } 
    result = ""+theTime2+":"+result; 
  }
  if(theTime3 > 0) { // 天
    theTime3 = parseInt(theTime3);
    result = ""+theTime3+" "+result; 
  }
  return result; 
}
timecount();  //倒计时
</script>
</html>

相关文章
|
6月前
|
C#
C# 如何使用倒计时
C# 如何使用倒计时
231 0
|
3月前
|
JavaScript
简单倒计时
【8月更文挑战第29天】原理:定的时间 -现在时间=时间差 讲时间差转换成时 分 秒 显示出来
32 0
|
5月前
|
前端开发 JavaScript
HTML+CSS+JS 倒计时动画效果
HTML+CSS+JS 倒计时动画效果
|
6月前
|
开发者 智能硬件
倒计时器
倒计时器
198 1
|
6月前
|
Python
|
6月前
做一个发送短信的倒计时按钮(很常用)
做一个发送短信的倒计时按钮(很常用)
35 0
|
6月前
uniapp实现倒计时
uniapp实现倒计时
134 0
|
JavaScript
[js倒计时]指定对应时间自动倒计时
[js倒计时]指定对应时间自动倒计时
181 0