php找一堆时间
php find a stack of time
我需要找到 If $now(00:00:00) 如果包含在 $a 和 $b
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";}
输出说:否
__________________EDIT____________________________
好的,谢谢大家,我想给你更多的信息:
我用 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() function 轻松获取数字格式的当前时间(从 1970-1-1 算起的秒数)。
您可以将日期转换为与 strtotime() function 相同的时间格式。
$now = time();
$a = strtotime("10 september 2010");
$b = strtotime("10 september 2020");
if( $now > $a && $now < $b )
echo "Yes";
else
echo "No";
我需要找到 If $now(00:00:00) 如果包含在 $a 和 $b
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";}
输出说:否
__________________EDIT____________________________
好的,谢谢大家,我想给你更多的信息:
我用 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() function 轻松获取数字格式的当前时间(从 1970-1-1 算起的秒数)。
您可以将日期转换为与 strtotime() function 相同的时间格式。
$now = time();
$a = strtotime("10 september 2010");
$b = strtotime("10 september 2020");
if( $now > $a && $now < $b )
echo "Yes";
else
echo "No";