PHP implementation posted in minutes/hours/days/months before the exact time

Source: Internet
Author: User
    1. /*
    2. * Precise time interval function
    3. * $time release time as 1356973323
    4. * $STR output format such as y-m-d h:i:s
    5. * The second half of the year is 15552000, 1 years is 31104000, here in half a year time
    6. */
    7. function From_time ($time, $str) {
    8. Isset ($STR)? $str: $str = ' m-d ';
    9. $way = Time ()-$time;
    10. $r = ";
    11. if ($way < 60) {
    12. $r = ' just ';
    13. }elseif ($way >= && $way <3600) {
    14. $r = Floor ($way/60). ' Minutes ago ';
    15. }elseif ($way >=3600 && $way <86400) {
    16. $r = Floor ($way/3600). ' Hours ago ';
    17. }elseif ($way >=86400 && $way <2592000) {
    18. $r = Floor ($way/86400). ' Days ago ';
    19. }elseif ($way >=2592000 && $way <15552000) {
    20. $r = Floor ($way/2592000). ' A month ago ';
    21. }else{
    22. $r = Date ("$str", $time);
    23. }
    24. return $r;
    25. }
Copy Code
  • 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.