请告诉我以下方法是否可靠地检查范围之间的当前日期
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));
}
我建议使用这样的日期时间对象:
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()));
}