How to query the time range in php

藏色散人
Release: 2023-03-14 19:06:02
Original
2814 people have browsed it

php method to query the time range: 1. Create a PHP sample file; 2. Use the "function checkIsBetweenTime($start,$end){...}" method to determine whether it is within the specified time range. Can.

How to query the time range in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to query the time range in php?

php Determine whether it is within the specified time period

/** * 判断当前的时分是否在指定的时间段内 * @param $start 开始时分 eg:10:30 * @param $end 结束时分 eg:15:30 * @author:mzc * @date:2018/8/9 10:46 * @return: bool 1:在范围内,0:没在范围内 */ function checkIsBetweenTime($start,$end){ $date= date('H:i'); $curTime = strtotime($date);//当前时分 $assignTime1 = strtotime($start);//获得指定分钟时间戳,00:00 $assignTime2 = strtotime($end);//获得指定分钟时间戳,01:00 $result = 0; if($curTime>$assignTime1&&$curTime<$assignTime2){ $result = 1; } return $result; } $assginTime1 = '00:00'; $assginTime2 = '01:00'; $isBetweenTime = checkIsBetweenTime($assginTime1,$assginTime2);
Copy after login

1. Judgment including hours and minutes

//设置【日期、时间】默认时区 date_default_timezone_set("Asia/Shanghai"); $time = intval (date("Hi")); if ($time > "800" && $time < "1130") { // code }
Copy after login

2. Judgment only Hours

date_default_timezone_set("Asia/Shanghai"); if(date('G')<8 || date('G')>17){ // code }$h = intval(date("H")); if($h > 23 || $h < 7){ echo '这里是第一个任务'; } else { echo '这里是第二个任务'; }
Copy after login

3. PHP judge statements by time period

$z && $z<$x){ echo '显示时间是00:00到00:29分之间'; } ?> //(亚洲/重庆) date_default_timezone_set('Asia/Chongqing'); //(亚洲/哈尔滨) date_default_timezone_set('Asia/Harbin'); //(中华人民共和国) date_default_timezone_set('PRC');
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to query the time range in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!