请告诉我以下方法是否可靠,以检查当前日期是否在范围之间
function check_in_range($start_date, $end_date)
{
// Convert to timestamp
$start_ts = strtotime($start_date);
$end_ts = strtotime($end_date)+86400;
//added 86400 to check for that particular date too
$timeNow = strtotime("now");
// Check that user date is between start & end
return (($timeNow >= $start_ts) && ($timeNow <= $end_ts));
}
答案 0 :(得分:0)
我建议使用日期时间对象,如下所示:
function check_in_range($start_date, $end_date)
{
$startDate = new \DateTime($start_date);
$endDate = new \DateTime($end_date);
$endDate->add(new \DateInterval('PT86400'));
return ((time() >= $startDate->getTimeStamp()) && (time() <= $endDate->getTimestamp()));
}