Compare time-size instances in PHP and php time-size instances

Source: Internet
Author: User

Compare time-size instances in PHP and php time-size instances

What is the time comparison of Shenma PHP?

The simplest example is to compare two times with a time greater than or less than a sign. Sometimes, when we design a program, we need to control the user's ability to operate a function only within a certain period of time, and the rest of the period is not allowed.

For example, I have a website that publishes messages. I publish messages on this website and then send them to thousands of users in a group. The common practice is to send messages to thousands of users immediately after a message is published. In this way, the user will receive a text message immediately as soon as there is the latest news. However, the problem arises. For example, if I publish information in the early morning of the night, it will be XXOO for all users.

Therefore, the time comparison can be used here. It can be released during the day and blocked at night. Let's assume that the daytime time period is from six o'clock P.M. am (it is estimated that many people are not awake) to AM, so we can do this.
Copy codeThe Code is as follows:
/**
* PHP time comparison
*/
// Define the start time. Note that the time is in string format, so it must be enclosed by quotation marks. Otherwise, do not contact me for an error. In addition, the colon must be an English colon.
$ Start_time = '7: 00 ';
 
// Define the end time. Never ask me why I wrote it at six o'clock P.M.. I suggest you reread the primary school.
$ End_time = '18: 00 ';
 
// Get the current time period. I will not talk about the use of the date () function. If you don't understand it, 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 publish the information! ';
} Else {
Echo 'Big Brother, what time is it now ~~~ People are not awake yet !!! ';
}

You need to note that the current time obtained is the server time. Therefore, pay attention to the time zone settings of the server time and whether the time zone is on time. Or you can submit a scheduled task to verify the time every day.


How does one compare the php time?

If you want to calculate attendance between $ time1 and $ time3, you can write
If ($ time2> $ time1 & $ time2 <$ time3 ){
Echo "Attendance ";
}
Else {
Echo "absent ";
}

Of course, it can also be written

If (strtotime ($ time2)> strtotime ($ time1) & strtotime ($ time2) <strtotime ($ time3 )){
Echo "Attendance ";
}
Else {
Echo "absent ";
}

How does one compare the php time?

The time can be compared in that way, but your condition is wrong. It should be?
If ($ time2> $ time1 & $ time2 <$ time3 ){
......

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.