[英]How would I compare specific time to the current time in PHP?
I am new to PHP and would like to compare a specific time with the current time. 我是PHP新手,想将特定时间与当前时间进行比较。 I have tried different tricks but nothing works for me.
我尝试了不同的技巧,但对我没有任何帮助。 Eg.
例如。
$my_time = '2:00';
$active='';
//echo "The time is " . date("h:ia");die;
if (date('h:i') > date('h:i', strtotime($myTime))) {
$active='Dinner';
$dinner=1;
}
else
{
$active='Lunch';
$lunch=1;
}
You have variable definition 您有变量定义
$my_time = '2:00'
but you're using 但是你在用
strtotime($myTime))
This might help you 这可能对您有帮助
$my_time ="14:08:10";
if (time() >= strtotime($my_time)) {
echo "Dinner";
}else echo "Lunch";
This will compare given time with current time 它将给定时间与当前时间进行比较
try this one . 试试这个。
$my_time ="14:08:10";
if (time() >= strtotime($my_time))
{
echo "Dinner";
}
else
{
echo "Lunch";
}
if this doesnt work try to add date in to time. 如果这样不起作用,请尝试添加日期。 because adding date will make time to be more specific.
因为添加日期将使时间更加具体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.