Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn [recommended] to determine whether the function is today/yesterday
// ================================================ ========
// This code is not perfect, and there may be some bad points. Please give me some advice!
// Author Zeng Qq839024615 can communicate with me
// ================================================ ========
// When we develop a cms system (your own small system), the development system is not counted for writing templates.
// We sometimes use the data to determine whether today is the data of yesterday, the data of today, and the data of yesterday.
// Etc.
// Today
Function JtColor ($ time ){
Date_default_timezone_set ('Asia/Shanghai ');
$ Jt = strtotime (date ('Y-m-d', time (). '00:00:00 ');
If ($ time> $ jt ){
Return 1; // If yes, 1 is returned.
} Else {
Return 0; // if not, return 0
}
}
// Retrieve from yesterday till now
Function ZtColor ($ time ){
Date_default_timezone_set ('Asia/Shanghai ');
$ Jt = strtotime (date ('Y-m-', time (). (date ('M', time ()-1). '00:00:00 ');
If ($ time> $ jt ){
Return 1; // If yes, 1 is returned.
} Else {
Return 0; // if not, return 0
}
}
// Let's see how we use it.
// If we retrieve a user's message today
$ Is = M ('login')-> order ('time desc')-> find (); // sort by message time
If (JtColor ($ is ['time']) {
Echo "if 1 is returned, the message is sent today ";
} Else {
Echo "if 0 is returned, the last message time is not today, that is, it is not posted after ";
}
// ================================================ ========
// This code is not perfect, and there may be some bad points. Please give me some advice!
// Author Zeng Qq839024615 can communicate with me
// ================================================ ========
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB