Php computing posts several minutes ago _ PHP Tutorial

Source: Internet
Author: User
Php computing posts a few minutes ago. The timeline development in php is displayed as "just", "5 minutes ago", and "Yesterday". if you need it, refer to it. The code is as follows: Copy the code functiontranTime ($ time) in php to develop the timeline, which is displayed as "just", "5 minutes ago", "Yesterday", etc, for more information, see.
The code is as follows:
Function tranTime ($ time ){
$ Rtime = date ("m-d H: I", $ time );
$ Htime = date ("H: I", $ time );

$ Time = time ()-$ time;

If ($ time <60 ){
$ Str = 'gang ';
}
Elseif ($ time <60*60 ){
$ Min = floor ($ time/60 );
$ Str = $ min. 'minute ago ';
}
Elseif ($ time <60*60*24 ){
$ H = floor ($ time/(60*60 ));
$ Str = $ h. 'hour before '. $ htime;
}
Elseif ($ time <60*60*24*3 ){
$ D = floor ($ time/(60*60*24 ));
If ($ d = 1)
$ Str = 'Yesterday '. $ rtime;
Else
$ Str = 'day before Day'. $ rtime;
}
Else {
$ Str = $ rtime;
}
Return $ str;
}

The $ time parameter in the tranTime () function must be a Unix Timestamp. if not, use strtotime () to convert it to a Unix timestamp.

Call

The code is as follows:

$ Times = "1286861696 ";
Echo tranTime ($ times );

Bytes. The code is as follows: function tranTime ($ time )...

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.