Provides various official and user-released code examples. For code reference, you are welcome to learn how to calculate the time difference between the given Timestamp and the current time, and output it in a friendly way.
/**
* Calculate the time difference between the given Timestamp and the current time, and output it in a friendly way
* @ Param [int] $ timestamp [given timestamp]
* @ Param [int] $ current_time [the timestamp to be subtracted from. The default value is the current time.]
* @ Return [string] [days of difference]
*/
Function tmspan ($ timestamp, $ current_time = 0 ){
If (! $ Current_time) $ current_time = time ();
$ Span = $ current_time-$ timestamp;
If ($ span <60 ){
Return "just now ";
} Else if ($ span <3600 ){
Return intval ($ span/60). "Minutes Ago ";
} Else if ($ span <24*3600 ){
Return intval ($ span/3600). "Hours Ago ";
} Else if ($ span <(7*24*3600 )){
Return intval ($ span/(24x3600). "Days Ago ";
} Else {
Return date ('Y-m-d', $ timestamp );
}
}
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB