You are here

protected static function WebformTime::formatTime in Webform 8.5

Same name in this branch
  1. 8.5 src/Element/WebformTime.php \Drupal\webform\Element\WebformTime::formatTime()
  2. 8.5 src/Plugin/WebformElement/WebformTime.php \Drupal\webform\Plugin\WebformElement\WebformTime::formatTime()
Same name and namespace in other branches
  1. 6.x src/Element/WebformTime.php \Drupal\webform\Element\WebformTime::formatTime()

Format custom time.

Parameters

string $custom_format: A PHP date format string suitable for input to date().

int $timestamp: (optional) A UNIX timestamp to format.

Return value

string Formatted time.

3 calls to WebformTime::formatTime()
WebformTime::preRenderWebformTime in src/Element/WebformTime.php
Adds form-specific attributes to a 'date' #type element.
WebformTime::validateWebformTime in src/Element/WebformTime.php
Webform element validation handler for #type 'webform_time'.
WebformTime::valueCallback in src/Element/WebformTime.php
Determines how user input is mapped to an element's #value property.

File

src/Element/WebformTime.php, line 205

Class

WebformTime
Provides a webform element for time selection.

Namespace

Drupal\webform\Element

Code

protected static function formatTime($custom_format, $timestamp = NULL) {

  /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
  $date_formatter = \Drupal::service('date.formatter');
  return $date_formatter
    ->format($timestamp ?: time(), 'custom', $custom_format);
}