PHP检查特定日期的下午5点
我目前正在尝试将当前时间与使用用户选择的日期计算的日期的下午5点进行比较。我尝试了不同的组合,并在谷歌上搜索了一下,但由于某种原因,我似乎不知道如何将下午5点定在选定的日期PHP检查特定日期的下午5点,php,date,Php,Date,我目前正在尝试将当前时间与使用用户选择的日期计算的日期的下午5点进行比较。我尝试了不同的组合,并在谷歌上搜索了一下,但由于某种原因,我似乎不知道如何将下午5点定在选定的日期 $expressFeeDate = date('Y-m-d', strtotime('+2 days', $arrivaldate_converted));// this line outputs 2018-01-08 for this current example $todaysDate = date("Y-m-d h:
$expressFeeDate = date('Y-m-d', strtotime('+2 days', $arrivaldate_converted));// this line outputs 2018-01-08 for this current example
$todaysDate = date("Y-m-d h:i:sa");// this line out puts the current date and time 2018-01-05 10:54:43am
我想在用户选择他们的日期后,计算expressFeeDate,因为它在上面的变量中,然后有另一个变量,它取该日期并输出2018-01-08 05:00:00pm
谢谢大家欢迎反馈。我将创建2个DateTime对象,并使用DateTime diff方法恢复间隔
$selectedDate = new \DateTime('2018-1-1');
$selectedDate->setTime(0, 17);
$today = new \DateTime('now');
$interval = $selectedDate->diff($today);
var_dump($interval); exit;
这将返回一个DateInterval对象,如下所示:
object(DateInterval)[959]
public 'y' => int 0
public 'm' => int 0
public 'd' => int 4
public 'h' => int 0
public 'i' => int 10
public 's' => int 0
public 'weekday' => int 0
public 'weekday_behavior' => int 0
public 'first_last_day_of' => int 0
public 'invert' => int 0
public 'days' => int 4
public 'special_type' => int 0
public 'special_amount' => int 0
public 'have_weekday_relative' => int 0
public 'have_special_relative' => int 0
现在,您可以简单地选择属性并使用所需的任何内容。我将创建2个DateTime对象,并使用DateTime diff方法返回间隔
$selectedDate = new \DateTime('2018-1-1');
$selectedDate->setTime(0, 17);
$today = new \DateTime('now');
$interval = $selectedDate->diff($today);
var_dump($interval); exit;
这将返回一个DateInterval对象,如下所示:
object(DateInterval)[959]
public 'y' => int 0
public 'm' => int 0
public 'd' => int 4
public 'h' => int 0
public 'i' => int 10
public 's' => int 0
public 'weekday' => int 0
public 'weekday_behavior' => int 0
public 'first_last_day_of' => int 0
public 'invert' => int 0
public 'days' => int 4
public 'special_type' => int 0
public 'special_amount' => int 0
public 'have_weekday_relative' => int 0
public 'have_special_relative' => int 0
现在,您可以简单地选择属性并使用所需的任何内容。我猜
date(“Y-m-d”,$expressDate)。“05:00:00pm”
可以执行以下操作trick@LatinSuD如何将当前时间转换为相同的格式以进行比较?我猜date(“Y-m-d”,$expressDate)。“05:00:00pm”
可以执行以下操作trick@LatinSuD如何将当前时间转换为相同的格式以进行比较?