God Horse system php time comparison?
The simplest example of this is the ability to compare two times to two times with a greater than less sign. Sometimes we design the program, need to control the user to operate a function can only be in a certain period of time to operate, the rest of the time period is not allowed.
For example, I have a website that posts messages, I post messages on this site, and then I send thousands of users through this message group. As a general practice, the message group should be sent to thousands of users as soon as the message is posted. In this way, as soon as the latest news, the user will be the first time to receive mobile phone messages. But here's the problem. For example, if I release the information in the early hours of the night, it will be xxoo by all users.
So, it can be used to compare time, if it can be published during daylight hours, then block at night. We assume that the daytime period is from seven in the morning (seven is estimated that a lot of people do not wake up) to six o'clock in the afternoon, then we can do so.
Copy the Code code as follows:
/**
* PHP Time Comparison
*/
Define the start time, notice that the time is a string format, so you must enclose the error in quotation marks Otherwise, do not call me, and the colon inside must be a colon
$start _time = ' 7:00 ';
Define the end time, don't ask me why I wrote 18 in the six o'clock in the afternoon, I would suggest you re-read primary school.
$end _time = ' 18:00 ';
Get the current time period, the use of the date () function I will not talk nonsense, do not understand directly read the previous article or Google
$now _time = Date (' h:i ');
Judge
if ($start _time<= $now _time && $end _time>= $now _time) {
Echo ' I want to post a message! ';
}else{
Echo ' elder brother, now only what time AH ~ ~ ~ People have not been awake yet!!! ';
}
Here you need to be reminded that the current time is server time, so please note the time zone setting and whether it is on time, or you can schedule a task to proofread it every day.