public function DateFormatter::getSampleDateFormats in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Datetime/DateFormatter.php \Drupal\Core\Datetime\DateFormatter::getSampleDateFormats()
Provides values for all date formatting characters for a given timestamp.
Parameters
string|null $langcode: (optional) Language code of the date format, if different from the site default language.
int|null $timestamp: (optional) The Unix timestamp to format, defaults to current time.
string|null $timezone: (optional) The timezone to use, if different from the site's default timezone.
Return value
array An array of formatted date values, indexed by the date format character.
Overrides DateFormatterInterface::getSampleDateFormats
See also
date()
File
- core/
lib/ Drupal/ Core/ Datetime/ DateFormatter.php, line 174 - Contains \Drupal\Core\Datetime\DateFormatter.
Class
- DateFormatter
- Provides a service to handle various date related functionality.
Namespace
Drupal\Core\DatetimeCode
public function getSampleDateFormats($langcode = NULL, $timestamp = NULL, $timezone = NULL) {
$timestamp = $timestamp ?: time();
// All date format characters for the PHP date() function.
$date_chars = str_split('dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU');
$date_elements = array_combine($date_chars, $date_chars);
return array_map(function ($character) use ($timestamp, $timezone, $langcode) {
return $this
->format($timestamp, 'custom', $character, $timezone, $langcode);
}, $date_elements);
}