admin 评论(0) 2021-02-25 PHP
  1. /**
  2. * 获取已经过了多久
  3. * PHP时间转换
  4. * 刚刚、几分钟前、几小时前
  5. * 今天昨天前天几天前
  6. * @param string $targetTime 时间戳
  7. * @return string
  8. */
  9. function get_last_time($targetTime)
  10. {
  11. // 今天最大时间
  12. $todayLast = strtotime(date('Y-m-d 23:59:59'));
  13. $agoTimeTrue = time() - $targetTime;
  14. $agoTime = $todayLast - $targetTime;
  15. $agoDay = floor($agoTime / 86400);
  16. if ($agoTimeTrue < 60) {
  17. $result = '刚刚';
  18. } elseif ($agoTimeTrue < 3600) {
  19. $result = (ceil($agoTimeTrue / 60)) . '分钟前';
  20. } elseif ($agoTimeTrue < 3600 * 12) {
  21. $result = (ceil($agoTimeTrue / 3600)) . '小时前';
  22. } elseif ($agoDay == 0) {
  23. $result = '今天 ' . date('H:i', $targetTime);
  24. } elseif ($agoDay == 1) {
  25. $result = '昨天 ' . date('H:i', $ta
    评论
      你来打破0评论