common.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 流年 <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. // 应用公共文件
  12. /**
  13. * 时间
  14. */
  15. function tranTime($utime)
  16. {
  17. $time = time() - $utime;
  18. if ($time < 60) {
  19. $str = '刚刚';
  20. } elseif ($time < 60 * 60) {
  21. $min = floor($time / 60);
  22. $str = $min.'分钟前';
  23. } elseif ($time < 60 * 60 * 24) {
  24. $h = floor($time / (60 * 60));
  25. $str = $h.'小时前';
  26. } elseif ($time < 60 * 60 * 24 * 3) {
  27. $d = floor($time / (60 * 60 * 24));
  28. if ($d == 1) {
  29. $str = '昨天';
  30. } else {
  31. $str = '前天';
  32. }
  33. } else {
  34. $str = date("m-d", $utime);
  35. }
  36. return $str;
  37. }