code: public function niceDate(\DateTime $date)
      {
          $now = $this->system->getDate();
  
          if ($now->format('Y-m-d') === $date->format('Y-m-d')) {
              return $date->format('H:i');
          } elseif ($now->format('Y-m') === $date->format('Y-m') && $date->format('d') + 1 == $now->format('d')) {
              return sprintf($this->translate('yesterday, %s'), $date->format('H:i'));
          }
  
          return $date->format('d-m-Y');
      }
docs: Create "nice" date
  
  @param \DateTime $date
  @return string