我的要求:
10
3
我应该如何更改代码以满足这些要求?
<?php
//$today_dt = new DateTime(date("H:i:s"));
//$today_dt = new DateTime(date("01:00:00")); **** Different result!!
$today_dt = new DateTime(date("01:00:00")); //**** Different result!!
$expire_dt1 = new DateTime(date("19:30:00"));
$expire_dt2 = new DateTime(date("08:00:00"));
if ($today_dt < $expire_dt1 && $today_dt < $expire_dt2){
$DateEnd = strtotime(date('10:30:00'));
echo '10';
}else{
$DateEnd = strtotime(date('H:i:s')." +3 hour");
echo '3';
}
echo '<br>'.date('H:i:s',$DateEnd);
?>
答案 0 :(得分:0)
新的一天开始......
$today_dt = new DateTime(date("01:00:00"));
首先是$expire_dt2 = new DateTime(date("08:00:00"));
然后是$expire_dt1 = new DateTime(date("19:30:00"));
所以我认为你必须进行适当的比较。
检查一下
var_dump($today_dt<$expire_dt1);
var_dump($today_dt<$expire_dt2);
两者都给出了真var_dump($expire_dt1>$expire_dt2); also gives true.So makes the following comparison ..hope it will works..
//$today_dt = new DateTime(date("H:i:s"));
//$today_dt = new DateTime(date("01:00:00")); **** Different result!!
$today_dt = new DateTime(date("01:00:00")); //**** Different result!!
$expire_dt1 = new DateTime(date("19:30:00"));
$expire_dt2 = new DateTime(date("08:00:00"));
// var_dump($today_dt<$expire_dt1);
// var_dump($today_dt<$expire_dt2);
// var_dump($expire_dt1>$expire_dt2);
if ($today_dt > $expire_dt1 && $today_dt < $expire_dt2){
$DateEnd = strtotime(date('10:30:00'));
echo '10';
}else{
$DateEnd = strtotime(date('H:i:s')." +3 hour");
echo '3';
}
echo '<br>'.date('H:i:s',$DateEnd);