function twig_date_format_filter

Converts a date to the given format.

<pre> {{ post.published_at|date("m/d/Y") }} </pre>

Parameters

Twig_Environment $env A Twig_Environment instance:

DateTime|DateInterval|string $date A date:

string $format A format:

DateTimeZone|string $timezone A timezone:

Return value

string The formatter date

1 string reference to 'twig_date_format_filter'
Twig_Extension_Core::getFilters in drupal/core/vendor/twig/twig/lib/Twig/Extension/Core.php
Returns a list of filters to add to the existing list.

File

drupal/core/vendor/twig/twig/lib/Twig/Extension/Core.php, line 383

Code

function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $timezone = null) {
  if (null === $format) {
    $formats = $env
      ->getExtension('core')
      ->getDateFormat();
    $format = $date instanceof DateInterval ? $formats[1] : $formats[0];
  }
  if ($date instanceof DateInterval || $date instanceof DateTime) {
    if (null !== $timezone) {
      $date = clone $date;
      $date
        ->setTimezone($timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone));
    }
    return $date
      ->format($format);
  }
  return twig_date_converter($env, $date, $timezone)
    ->format($format);
}