This hook is executed whenever \Contao\Date::parse
is used. \Contao\Date::parse
allows you to format a date (timestamp) using the locale of the current request.
The hook allows you to customize the date format.
string `$formattedDate
The already formatted date.
string $format
The requested date format.
int $timestamp
The given timestamp. Can be null
.
A string containing the formatted date.
// src/EventListener/ParseDateListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
#[AsHook('parseDate')]
class ParseDateListener
{
public function __invoke(string $formattedDate, string $format, ?int $timestamp): string
{
// Modify or create your own formatted date …
return $formattedDate;
}
}