public static function YamlFormDateHelper::format in YAML Form 8
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
3 calls to YamlFormDateHelper::format()
- template_preprocess_yamlform_submission_information in includes/
yamlform.theme.inc - Prepares variables for form submission information template.
- template_preprocess_yamlform_submission_text in includes/
yamlform.theme.inc - Prepares variables for form submission plain text template.
- yamlform_tokens in ./
yamlform.tokens.inc - Implements hook_tokens().
File
- src/
Utility/ YamlFormDateHelper.php, line 35
Class
- YamlFormDateHelper
- Helper class form date helper methods.
Namespace
Drupal\yamlform\UtilityCode
public static function format($timestamp, $type = 'fallback', $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) : '';
}