public static function WebformDateHelper::format in Webform 8.5
Same name and namespace in other branches
- 6.x src/Utility/WebformDateHelper.php \Drupal\webform\Utility\WebformDateHelper::format()
Wrapper for DateFormatter that return an empty string for empty timestamps.
Parameters
int $timestamp: A UNIX timestamp to format.
string $type: (optional) The data format to use.
string $format: (optional) If $type is 'custom', a PHP date format string suitable for element 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. An empty string will be returned for empty timestamps.
See also
\Drupal\Core\Datetime\DateFormatterInterface::format
2 calls to WebformDateHelper::format()
- template_preprocess_webform_submission_information in includes/
webform.theme.template.inc - Prepares variables for webform submission information template.
- webform_tokens in ./
webform.tokens.inc - Implements hook_tokens().
File
- src/
Utility/ WebformDateHelper.php, line 54
Class
- WebformDateHelper
- Helper class webform date helper methods.
Namespace
Drupal\webform\UtilityCode
public static function format($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = \Drupal::service('date.formatter');
return $timestamp ? $date_formatter
->format($timestamp, $type, $format, $timezone, $langcode) : '';
}