Calculation function of the number of days before the message release time

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

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.