dateTime = $dateTime; $this->dateTimeFormat = $dateTimeFormat; } public function formatDate($datetime) { $now = new \DateTime(); $ago = new \DateTime($datetime); $diff = $now->diff($ago); $string = [ 'h' => 'hour', 'i' => 'minute', 's' => 'second', ]; foreach ($string as $k => &$v) { if ($diff->$k) { $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : ''); } else { unset($string[$k]); } } $hours = isset($string['h']) ? $string['h'] : ''; $minutes = isset($string['i']) ? $string['i'] : ''; $seconds = isset($string['s']) && !isset($string['h']) ? $string['s'] : ''; return __('%1 ago', $hours . ' ' . $minutes . ' ' . $seconds); } }