1. public function smarttimeFilter($time)
    2. {
    3. $diff = time() - $time;
    4. if ($diff < 0) {
    5. return $this->getServiceKernel()->trans('未来');
    6. }
    7. if ($diff == 0) {
    8. return $this->getServiceKernel()->trans('刚刚');
    9. }
    10. if ($diff < 60) {
    11. return $diff.$this->getServiceKernel()->trans('秒前');
    12. }
    13. if ($diff < 3600) {
    14. return round($diff / 60).$this->getServiceKernel()->trans('分钟前');
    15. }
    16. if ($diff < 86400) {
    17. return round($diff / 3600).$this->getServiceKernel()->trans('小时前');
    18. }
    19. if ($diff < 2592000) {
    20. return round($diff / 86400).$this->getServiceKernel()->trans('天前');
    21. }
    22. if ($diff < 31536000) {
    23. return date('m-d', $time);
    24. }
    25. return date('Y-m-d', $time);
    26. }