function DateTimeCustomFormatter::formatDate

Same name and namespace in other branches
  1. 8.9.x core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeCustomFormatter::formatDate()
  2. 10 core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeCustomFormatter::formatDate()
  3. 11.x core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeCustomFormatter::formatDate()

Overrides DateTimeFormatterBase::formatDate

File

core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php, line 56

Class

DateTimeCustomFormatter
Plugin implementation of the 'Custom' formatter for 'datetime' fields.

Namespace

Drupal\datetime\Plugin\Field\FieldFormatter

Code

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.