Formats a date, using a date type or a custom date format string.
$timestamp: A UNIX timestamp to format.
$type: (optional) The format to use, one of:
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.
A translated date string in the requested format.
\Drupal\Component\Datetime\Date::format()
function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
return Drupal::service('date')
->format($timestamp, $type, $format, $timezone, $langcode);
}