我试图在我的网站上获得一个倒计时系统,从注册时间开始只有24小时倒计时。PHP中的日期差异
这个想法是注册后,订户有24小时付款后,他将被阻止。我的注册时间已经在我的数据库中,但我陷入了倒计时。我在网上尝试了几种帮助,但我似乎没有把它做对。
JavaScript设置为用户付款的剩余秒数var count = '86400';
但我想使用php来计算从注册时间到当前时间他已注册多长时间,以便当我刷新该页面,它不会从当前剩余时间开始。所以我做了这个var count = <?php echo strtotime($row_rsPH['date'])-time(); ?>;
<script type="text/javascript">
var count = <?php echo strtotime($row_rsPH['date'])-time(); ?>;
var counter = setInterval(timer, 1000);
function timer() {
count = count - 1;
if (count == -1) {
clearInterval(counter);
return;
}
var seconds = count % 60;
var minutes = Math.floor(count/60);
var hours = Math.floor(minutes/60);
minutes %= 60;
hours %= 60;
document.getElementById("timer").innerHTML = hours + ":" + minutes + ":" + seconds; // watch for spelling
}
function startTimer(duration, display) {
var start = Date.now(),
diff,
minutes,
seconds;
function timer() {
// get the number of seconds that have elapsed since
// startTimer() was called
diff = duration - (((Date.now() - start)/1000) | 0);
// does the same job as parseInt truncates the float
minutes = (diff/60) | 0;
seconds = (diff % 60) | 0;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.textContent = minutes + ":" + seconds;
if (diff <= 0) {
// add one second so that the count down starts at the full duration
// example 05:00 not 04:59
start = Date.now() + 1000;
}
};
// we don't want to wait a full second before the timer starts
timer();
setInterval(timer, 1000);
}
</script>
<p>Time Left to make payment: <span id='timer'></span></p>
http://php.net/ manual/en/datetime.sub.php – Sammitch
你有这个任何PHP?它被标记为这样的 –
嗨@ Fred-ii-是的,我做'<?php回声strtotime($ row_rsPH ['date']) - time(); ?>' – Jahswey