You are here

function twig_date_format_filter in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Twig/Extension/Core.php \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|DateTimeInterface|DateInterval|string $date A date:

string|null $format The target format, null to use the default:

DateTimeZone|string|null|false $timezone The target timezone, null to use the default, false to leave unchanged:

Return value

string The formatted date

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

File

vendor/Twig/Extension/Core.php, line 454

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) {
    return $date
      ->format($format);
  }
  return twig_date_converter($env, $date, $timezone)
    ->format($format);
}