The timeline development in php is displayed as "just", "5 minutes ago", and "Yesterday"

Source: Internet
Author: User
The timeline development in php is very useful in development such as just five minutes ago and yesterday, such as forum posts, the bib has related applications. // The time conversion function functiontranTime ($ time) {$ rtime = date (m-dH: I, $ time); $ htime = date (H: i, $ time );

The timeline development in php is displayed as "just", "5 minutes ago", "Yesterday", etc.

It is quite useful during development, such as forum posts and collars.

 

 
 
  1. // Time conversion function
  2. Function tranTime ($ time ){
  3. $ Rtime = date ("m-d H: I", $ time );
  4. $ Htime = date ("H: I", $ time );
  5. $ Time = time ()-$ time;
  6. If ($ time <60 ){
  7. $ Str = 'gang ';
  8. }
  9. Elseif ($ time <60*60 ){
  10. $ Min = floor ($ time/60 );
  11. $ Str = $ min. 'minute ago ';
  12. }
  13. Elseif ($ time <60*60*24 ){
  14. $ H = floor ($ time/(60*60 ));
  15. $ Str = $ h. 'hour before '. $ htime;
  16. }
  17. Elseif ($ time <60*60*24*3 ){
  18. $ D = floor ($ time/(60*60*24 ));
  19. If ($ d = 1)
  20. $ Str = 'Yesterday '. $ rtime;
  21. Else
  22. $ Str = 'day before Day'. $ rtime;
  23. }
  24. Else {
  25. $ Str = $ rtime;
  26. }
  27. Return $ str;
  28. }

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 function and directly output the following:

 
 
  1. $times="1286861696 ";    
  2. echo tranTime($times);  

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.