protected function DateTimeCustomFormatter::formatDate in Drupal 10
Same name and namespace in other branches
- 8 core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeCustomFormatter::formatDate()
- 9 core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeCustomFormatter::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
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\FieldFormatterCode
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);
}