倒数倒计时

时间:2015-07-02 00:19:55

标签: javascript php html

谁能帮帮我?例如,我想要countdown timer但反转,例如:

我在javascript或mysqL中插入我的日期和小时(没关系),它会计算在内。

示例:我插入:01/07/2015

今天柜台将显示:1天1小时19分钟

2 个答案:

答案 0 :(得分:1)

由于您想使用jQuery Countdown插件,您可以使用它的内置计数功能。查看jQuery倒计时页面的“Count Up”选项卡:http://keith-wood.name/countdown.html

编辑:添加代码示例

$("#countdown").countdown({since: new Date(2015, 7-1, 1)});
#countdown {
  float: left;
  width: 240px;
}
<link href="http://keith-wood.name/css/jquery.countdown.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://keith-wood.name/js/jquery.plugin.js"></script>
<script src="http://keith-wood.name/js/jquery.countdown.js"></script>

<span id="countdown">

答案 1 :(得分:1)

如果您不想使用jquery,那么您可以执行以下操作:

var startTime = +new Date("07/01/2015"); // m/d/Y gets timestamp in ms

var second = 1000;
var minute = second * 60;
var hour = minute * 60;
var day = hour * 24;

var element = document.getElementById('timer'); // target element for the timer

function countUp() {
  // time between now and the start date
  var time = Date.now() - startTime;

  // days passed since start
  var days = Math.floor(time / day);
  time -= days * day;

  // hours passed
  var hours = Math.floor(time / hour);
  time -= hours * hour;

  // minutes passed
  var minutes = Math.floor(time / minute);

  // update element
  element.innerHTML = days + 'day ' + hours + 'hour ' + minutes + 'min';

  setTimeout(countUp, minute);
};

countUp();
<span id="timer"></span>