在PHP中,如何在第二天的某个时间获取?
我需要检查PHP中的日期是否大于第二天的00:00小时。 乍一看,我试图使用在PHP中,如何在第二天的某个时间获取?,php,date,time,strtotime,days,Php,Date,Time,Strtotime,Days,我需要检查PHP中的日期是否大于第二天的00:00小时。 乍一看,我试图使用 if($date_variable<strtotime('+1day')){ return true; }else{ return false } 如果($date\u variable您可以像这样尝试使用mktime(): if($date_variable<mktime(0,0,0, date('m'), date('d')+1, date('Y')){ return true; }
if($date_variable<strtotime('+1day')){
return true;
}else{
return false
}
如果($date\u variable您可以像这样尝试使用mktime():
if($date_variable<mktime(0,0,0, date('m'), date('d')+1, date('Y')){
return true;
}else{
return false
}
如果($date\u variable您可以像这样尝试使用mktime():
if($date_variable<mktime(0,0,0, date('m'), date('d')+1, date('Y')){
return true;
}else{
return false
}
如果($date\u变量您可以使用:
if($date_variable<strtotime('midnight tomorrow')){
return true;
}else{
return false
}
如果($date\u变量您可以使用:
if($date_variable<strtotime('midnight tomorrow')){
return true;
}else{
return false
}
if($date\u variable好的,现在接受的答案已经超过三年了,因为我们得到了PHP5,甚至现在有了PHP7,我们可以用DateTime
类来做得更容易。DateTime
类是一个原生PHP类。不需要更多的库
$oDateNow = new DateTime(); // Date now
$oDateTomorrow = new DateTime('tomorrow midnight'); // Date tomorrow midnight
$bResult = $oDateNow < $oDateTomorrow ? true : false;
$oDateNow=new DateTime();//现在开始日期
$oDateTomorrow=新的日期时间(“明天午夜”);//日期明天午夜
$bResult=$oDateNow<$oDateTomorrow?真:假;
DateTime
类接受所有参数strotime()
函数也接受。好的,被接受的答案现在已经三年多了,因为我们有了PHP5,甚至现在有了PHP7,我们可以用DateTime
类做得更容易。DateTime
类是一个原生PHP类。不需要更多的库
$oDateNow = new DateTime(); // Date now
$oDateTomorrow = new DateTime('tomorrow midnight'); // Date tomorrow midnight
$bResult = $oDateNow < $oDateTomorrow ? true : false;
$oDateNow=new DateTime();//现在开始日期
$oDateTomorrow=新的日期时间(“明天午夜”);//日期明天午夜
$bResult=$oDateNow<$oDateTomorrow?真:假;
DateTime
类接受所有参数strotime()
函数也接受。是$date\u变量是DateTime对象吗?是使用unix时间戳还是y-m-d H-i-s格式?@Xfile似乎是unix时间戳,因为strotime返回时间戳是$date\u变量是DateTime对象吗?是使用unix时间戳还是y-m-d H-i-s格式?@Xfile似乎是unix时间戳,因为strotime返回时间戳耶!谢谢很多哥们。我有一种“我有它在我眼前,但我看不见它”的感觉。我会使用Nils解决方案,因为它的代码更小,但非常感谢你的帮助。见鬼,是的!非常感谢哥们。我有一种“我有它在我眼前,但我看不见它”的感觉.我将使用Nils解决方案,因为它的代码较小,但非常感谢您的帮助。