PHP timeline Development, which is displayed as "just", "5 minutes Ago", "Yesterday 10:23

Source: Internet
Author: User
Tags min php timeline

PHP timeline Development, which is displayed as "just", "5 minutes Ago", "Yesterday 10:23" and so on

Development is still very useful, such as forum posts, scarf and other related applications

 
 
  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 = ' just ';
  8. }
  9. ElseIf ($time < 60 * 60) {
  10. $min = Floor ($time/60);
  11. $str = $min. ' Minutes ago ';
  12. }
  13. ElseIf ($time < 60 * 60 * 24) {
  14. $h = Floor ($time/(60*60));
  15. $str = $h. ' Hour ago '. $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 yesterday '. $rtime;
  23. }
  24. else {
  25. $str = $rtime;
  26. }
  27. return $str;
  28. }

The parameter $time in the function trantime () must be a Unix timestamp, and if not, convert it to a UNIX timestamp using Strtotime ().

Call function, Direct output:

 
  
  
  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.