我在基于两个预先指定的时间比较当前时间时遇到了问题。让我告诉你我想要什么:如果当前时间在晚上10点到早上8点之间,我想显示一条消息我的代码是
$current_time = strtotime('now');
if ( $current_time > strtotime('10:00pm') && $current_time < strtotime('8:00am') ) {
//Display message
}但是它不起作用,因为在12:00 in之后,strtotime(‘10:00 in’)正在计算今天的10 in值,并且在给定的条件下无法传递。所以我需要你的建议。
发布于 2013-05-09 14:37:23
date("G", strtotime("now"))将显示24小时格式,不带前导零。
你想要的代码是:
$current_hour = date("G", strtotime("now"));
if ($current_hour >= 22 || $current_hour < 8) {
//Display message
}发布于 2013-05-09 14:08:42
尝尝这个,
$current_hour = date("G", strtotime("now"));
if ($current_hour > 23 || $current_hour < 8) {
if ( $current_time > strtotime('10:00pm -1 Day') && $current_time < strtotime('8:00am') ) { //after
//Display message
}
}else{
if ( $current_time > strtotime('10:00pm') && $current_time < strtotime('8:00am +1 Day') ) {
//Display message
}
}https://stackoverflow.com/questions/16454482
复制相似问题