function DateFormatterInterface::format

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Datetime/DateFormatterInterface.php \Drupal\Core\Datetime\DateFormatterInterface::format()
  2. 10 core/lib/Drupal/Core/Datetime/DateFormatterInterface.php \Drupal\Core\Datetime\DateFormatterInterface::format()
  3. 11.x core/lib/Drupal/Core/Datetime/DateFormatterInterface.php \Drupal\Core\Datetime\DateFormatterInterface::format()

Formats a date, using a date type or a custom date format string.

Parameters

int $timestamp: A UNIX timestamp to format.

string $type: (optional) The format to use, one of:

  • One of the built-in formats: 'short', 'medium', 'long', 'html_datetime', 'html_date', 'html_time', 'html_yearless_date', 'html_week', 'html_month', 'html_year'.
  • The name of a date type defined by a date format config entity.
  • The machine name of an administrator-defined date format.
  • 'custom', to use $format.

Defaults to 'medium'.

string $format: (optional) If $type is 'custom', a PHP date format string suitable for input to date(). Use a backslash to escape ordinary text, so it does not get interpreted as date format characters.

string|null $timezone: (optional) Time zone identifier, as described at http://php.net/manual/timezones.php Defaults to the time zone used to display the page.

string|null $langcode: (optional) Language code to translate to. NULL (default) means to use the user interface language for the page.

Return value

string A translated date string in the requested format. Since the format may contain user input, this value should be escaped when output.

1 method overrides DateFormatterInterface::format()
DateFormatter::format in core/lib/Drupal/Core/Datetime/DateFormatter.php
Formats a date, using a date type or a custom date format string.

File

core/lib/Drupal/Core/Datetime/DateFormatterInterface.php, line 40

Class

DateFormatterInterface
Provides an interface defining a date formatter.

Namespace

Drupal\Core\Datetime

Code

public function format($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL);

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