PHP倒计时时间表
我有过这样的经历:PHP倒计时时间表,php,Php,我有过这样的经历: 08:00 09:00 10:00 11:00 12:00 13:00 14:00 15:00 我怎样才能把这个时间表变成倒计时?因此,例如,如果时间是06:45,它会说: 1:15 left until 1 (number of the time) 如果时间超过08:00,则会显示: 1:00 left until 2 (number of the time) 编辑: 我试过了,但有点不对劲: $bellday = date("N"); $time = date('H
08:00
09:00
10:00
11:00
12:00
13:00
14:00
15:00
我怎样才能把这个时间表变成倒计时?因此,例如,如果时间是06:45
,它会说:
1:15 left until 1 (number of the time)
如果时间超过08:00
,则会显示:
1:00 left until 2 (number of the time)
编辑:
我试过了,但有点不对劲:
$bellday = date("N");
$time = date('H:i');
define('TIME', $time);
$bell = array
(
1 => '8:00',
2 => '9:00',
3 => '10:00',
4 => '11:00',
5 => '12:00',
6 => '13:00',
7 => '14:00',
8 => '15:00'
);
function getTime($time)
{
$date = strtotime($time);
$time = abs($date - strtotime(TIME));
$hours = (int)($time / 3600);
$min = (int)(($time - $hours * 3600) / 60);
if($hours == 0)
$hours = '';
else
$hours = $hours.":";
$bellinfo = "$hours$min left";
}
这应该适合您:
<?php
$times = array("08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00");
$input = "08:00";
foreach($times as $k => $v) {
$temp = new DateTime("$v");
$time = new DateTime("$input");
if($v ==$last = end($times))
echo $input . " is later then any time in the array!";
if($time >= $temp) {
continue;
} else {
$left = $time->diff($temp);
printf('%d hours, %d minutes left until %d (number of the time)', $left->h, $left->i, $k+1);
break;
}
}
?>
编写代码将是一个很好的开始…@Rizier123抱歉,我编辑了这篇文章并包含了我已经拥有并尝试过的内容。@MarcB抱歉,我编辑了这篇文章并包含了我已经拥有并尝试过的内容。您的函数不会返回anything@MarkMiner我想你在寻找我的答案?
1 hours, 0 minutes left until 2 (number of the time)