You are here

protected function DateTimeDefaultFormatter::formatDate in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeDefaultFormatter::formatDate()

Creates a formatted date value as a string.

Parameters

object $date: A date object.

Return value

string A formatted date string using the chosen format.

Overrides DateTimeFormatterBase::formatDate

1 call to DateTimeDefaultFormatter::formatDate()
DateTimeDefaultFormatter::settingsSummary in core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php
Returns a short summary for the current formatter settings.

File

core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php, line 33

Class

DateTimeDefaultFormatter
Plugin implementation of the 'Default' formatter for 'datetime' fields.

Namespace

Drupal\datetime\Plugin\Field\FieldFormatter

Code

protected function formatDate($date) {
  $format_type = $this
    ->getSetting('format_type');
  $timezone = $this
    ->getSetting('timezone_override') ?: $date
    ->getTimezone()
    ->getName();
  return $this->dateFormatter
    ->format($date
    ->getTimestamp(), $format_type, '', $timezone != '' ? $timezone : NULL);
}