function format_date in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/includes/common.inc \format_date()
Formats a date, using a date type or a custom date format string.
Parameters
$timestamp: A UNIX timestamp to format.
$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'.
$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.
$timezone: (optional) Time zone identifier, as described at http://php.net/manual/timezones.php Defaults to the time zone used to display the page.
$langcode: (optional) Language code to translate to. Defaults to the language used to display the page.
Return value
A translated date string in the requested format.
Deprecated
in Drupal 8.0.0, will be removed before Drupal 9.0.0. Use \Drupal::service('date.formatter')->format().
See also
\Drupal\Core\Datetime\DateFormatter::format()
Related topics
53 calls to format_date()
- CommentAttributesTest::_testBasicCommentRdfaMarkup in core/
modules/ rdf/ src/ Tests/ CommentAttributesTest.php - Helper function for testCommentRdfaMarkup().
- CommentPreviewTest::testCommentEditPreviewSave in core/
modules/ comment/ src/ Tests/ CommentPreviewTest.php - Tests comment edit, preview, and save.
- CommentTranslationUITest::doTestAuthoringInfo in core/
modules/ comment/ src/ Tests/ CommentTranslationUITest.php - Tests the translation authoring information.
- comment_tokens in core/
modules/ comment/ comment.tokens.inc - Implements hook_tokens().
- ConfigTranslationUiTest::testDateFormatTranslation in core/
modules/ config_translation/ src/ Tests/ ConfigTranslationUiTest.php - Tests date format translation.
1 string reference to 'format_date'
- TwigExtension::getFilters in core/
lib/ Drupal/ Core/ Template/ TwigExtension.php
File
- core/
includes/ common.inc, line 323 - Common functions that many Drupal modules will need to reference.
Code
function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
return \Drupal::service('date.formatter')
->format($timestamp, $type, $format, $timezone, $langcode);
}