Php倒计时脚本

时间:2012-03-10 21:28:27

标签: php

我正在尝试使用PHP制作倒计时脚本。我已经成功完成了第一部分,我从72开始倒计时。导致我麻烦的是找出如何在$hours < 1时分钟倒计时。

代码:

date_default_timezone_set('Europe/Copenhagen');
$connect = mysql_connect('localhost', 'root', '');
$db = mysql_select_db('time');

$sql = "SELECT time FROM timeanddate";

$qry = mysql_query($sql);
$row = mysql_fetch_assoc($qry);


$start_time = date("H:i:s", strtotime($row['time']));

$current_time = date("H:i:s");

function dateDiff($start, $end) {

 $start_ts = strtotime($start);

 $end_ts = strtotime($end);

 $diff = $end_ts - $start_ts;

 return round($diff / 3600);

}

$count = dateDiff($row['time'], $current_time);

$hours = 72;

$hours_left = $hours - $count;

echo $hours_left . " Hours back <br />";

1 个答案:

答案 0 :(得分:0)

乘以60.例如,0.5小时* 60 = 30分钟:

if($hours_left > 1) {
    echo $hours_left . " Hours left <br />";
} else if() {
    echo "1 Hour left<br />";
} else {
    echo ceil($hours_left * 60) . " Minutes left";
}