php找到一堆时间


php find a stack of time

如果$a和$b 中包含If$now(00:00:00),我需要查找

echo $a= date('H:i:s', strtotime("23:00:00"));
echo $now = date('H:i:s', time("now");*(es.00:00:00)*
echo $b=date('H:i:s', strtotime("01:00:00"));
if ($now>$a && $now<$b) {echo "si";} else {echo "no";}

输出说:没有

__________________编辑____________________________

好的,谢谢大家,我想给你更多的信息:

我用php读取了一个.xml文件,从这个文件中,我得到了一些关于电视节目的信息,其中包括:

-节目名称,-频道名称,-以及节目开始时间(20151210004500+0100)

我认为在这一点上使用这种格式更容易,还是不容易?

我会在.xml的数组中找到正在播放的程序,为了做到这一点,我必须比较这种格式的日期和时间,这可能吗?

你能帮我吗?

抱歉我英语不好,谢谢。

在比较之前应用strtotime

if(strtotime($now) > strtotime($a) && strtotime($now) < strtotime($b)     
{ 
    // do your staff 
}
$now = new DateTime;
$a = (new DateTime)->setTime(23, 0, 0);
if ($now > $a && $now < $a->modify('+2 hours')) {
    echo 'si';
} else {
    echo 'no';
}

使用time()函数可以很容易地获得数字格式的当前时间(1970-1-1中的秒)。

然后您可以使用strtotime()函数将日期转换为相同的时间格式。

$now = time();
$a = strtotime("10 september 2010");
$b = strtotime("10 september 2020");
if( $now > $a && $now < $b )
    echo "Yes";
else
    echo "No";