Home >Backend Development >PHP Tutorial >Two ways to determine a specified time period in PHP_PHP Tutorial
Sometimes we need to perform a certain task at a certain time of the day, or perform different tasks at different hours of the day. How to achieve this using PHP? The following two examples can solve this problem. Question
1. Judgment including hours and minutes The code is as follows: date_default_timezone_set("Asia/Shanghai"); $time = intval (date("Hi")); if ($time > "800" && $time < "1130") { // code } 2. Only judge the hour The code is as follows: date_default_timezone_set("Asia/Shanghai"); if(date('G')<8 || date('G')>17) { // code }$h = intval(date("H")); if ($h > 23 || $h < 7) { echo 'Here is the first task'; } else { echo 'This is the second task'; }