You are here

protected static function DateBase::formatDate in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/DateBase.php \Drupal\webform\Plugin\WebformElement\DateBase::formatDate()

Format custom date.

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 date.

8 calls to DateBase::formatDate()
Date::form in src/Plugin/WebformElement/Date.php
Gets the actual configuration webform array to be built.
Date::setDefaultValue in src/Plugin/WebformElement/Date.php
Set an element's default value using saved data.
DateBase::formatTextItem in src/Plugin/WebformElement/DateBase.php
Format an element's value as text.
DateBase::getTestValues in src/Plugin/WebformElement/DateBase.php
Get test values for an element.
DateBase::prepare in src/Plugin/WebformElement/DateBase.php
Prepare an element to be rendered within a webform.

... See full list

File

src/Plugin/WebformElement/DateBase.php, line 698

Class

DateBase
Provides a base 'date' class.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected static function formatDate($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);
}