function DateTimeDefaultFormatter::formatDate

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

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);
}

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