php检查现在的时间是否在周日的09:00到12:00之间
我正在尝试编写一个php代码来检查它是否是周日早上(09:00到12:00之间) 它应该100%有效,但我看不出我做错了什么php检查现在的时间是否在周日的09:00到12:00之间,php,Php,我正在尝试编写一个php代码来检查它是否是周日早上(09:00到12:00之间) 它应该100%有效,但我看不出我做错了什么 <?php date_default_timezone_set('Europe/Stockholm'); // timezone $date = strtotime(time()); if ((date('w', $date) == 0 && date('H', $date) >= 09) || (dat
<?php
date_default_timezone_set('Europe/Stockholm'); // timezone
$date = strtotime(time());
if ((date('w', $date) == 0 && date('H', $date) >= 09) ||
(date('w', $date) == 0 && date('H', $date) <= 12)) {
echo "yes, it´s sunday morning";
} else {
echo 'nope, not sunday morning anymore';
}
?>
注:这只是任何给定的星期日-没有确定的日期
不确定时区脚本是否是问题所在
现在,无论我是否将值从12更改为18,它都会显示“不,不是星期天上午”给定的代码只是检查当天是否是星期天。这将检查周日上午:
<?php
date_default_timezone_set('Europe/Stockholm'); // timezone
$date = strtotime(time());
if ((date('w', $date) == 0 && date('H', $date) >= 09) && date('H', $date) <= 12)) {
echo "yes, it´s sunday morning";
} else {
echo 'nope, not sunday morning anymore';
}
?>
试试:
您的代码是错误的,星期天中的每一次都是在9之后(日期('w',$date)==0
&&日期('H',$date)>=09)或12日之前(日期('w',$date)==0&&date('H',$date)尝试以下方法:
<?php
date_default_timezone_set('Europe/Stockholm');
$current_day = date("w");//get the current day : 0 is sunday
$time_now = date("H:i:s");
echo $current_day;
echo($time_now);
if($current_day == 0){//today it is sunday
if($time_now >= "09:00:00" && $time_now <="12:00:00"){
echo "yes, it´s sunday morning";
}
else{
echo "yes, it´s sunday but not morning";
}
}
else{
echo 'nope, not sunday';
}
很好!…作为一个润滑良好的雪佛兰发动机工作-很好…好吧,看到结构变得更有意义了
<?php
date_default_timezone_set('Europe/Stockholm');
$current_day = date("w");//get the current day : 0 is sunday
$time_now = date("H:i:s");
echo $current_day;
echo($time_now);
if($current_day == 0){//today it is sunday
if($time_now >= "09:00:00" && $time_now <="12:00:00"){
echo "yes, it´s sunday morning";
}
else{
echo "yes, it´s sunday but not morning";
}
}
else{
echo 'nope, not sunday';
}