dateFormatter = $date_formatter; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('date.formatter') ); } /** * Builds the response. */ public function build() { $build['content'] = [ '#type' => 'item', '#title' => $this->t('Content'), '#markup' => $this->t('Hello world!'), ]; $build['date'] = [ '#type' => 'item', '#title' => $this->t('Date'), '#markup' => $this->dateFormatter->format(REQUEST_TIME), ]; return $build; } }