You are here

protected static function WebformTime::formatTime in Webform 6.x

Same name in this branch
  1. 6.x src/Element/WebformTime.php \Drupal\webform\Element\WebformTime::formatTime()
  2. 6.x src/Plugin/WebformElement/WebformTime.php \Drupal\webform\Plugin\WebformElement\WebformTime::formatTime()
Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/WebformTime.php \Drupal\webform\Plugin\WebformElement\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.

2 calls to WebformTime::formatTime()
WebformTime::form in src/Plugin/WebformElement/WebformTime.php
Gets the actual configuration webform array to be built.
WebformTime::formatTextItem in src/Plugin/WebformElement/WebformTime.php
Format an element's value as text.

File

src/Plugin/WebformElement/WebformTime.php, line 156

Class

WebformTime
Provides a 'webform_time' element.

Namespace

Drupal\webform\Plugin\WebformElement

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 ?: \Drupal::time()
    ->getRequestTime(), 'custom', $custom_format);
}