Compare time-size instances in PHP _php instances

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.