我在一个页面上有一个选项,如果页面在5到1小时和15分钟过去一小时之间加载,而没有放入24个不同的时间,有没有更简单的方法来做到这一点?由于
if (($time > 'five to the hour') && ($time < 'quarter past the hour')){
//do something
}
else {}
您可以使用mktime()
来制作时间戳。
$current_hour = date('H') - 1;
if($current_hour < 0) {
$current_hour = 23;
}
$time_before = mktime($current_hour, 55, 0);
$time_after = mktime(date('H'), 16, 0);
if($time_before <= time() AND $time_after > time()) {
//Do Something
}
试试这样:
if (intval(date('i', time())) > 15 && intval(date('i', time())) < 55) {
// any time from hour:16 to hour:54, inclusive
} else {
// any time until hour:15 or from hour:55
}