Home > Backend Development > PHP Tutorial > Two ways to determine a specified time period in PHP_PHP Tutorial

Two ways to determine a specified time period in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 10:35:50
Original
1094 people have browsed it

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'; } ​

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/741820.htmlTechArticleSometimes we need to perform a certain task at a certain time of the day, or at different hours of the day How to perform different tasks using PHP? The following two examples can be...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template