I’m storing all my dates as UTC in the database. But I want to display them in the users timezone.
$mydate = new DateTime('2024-08-07 12:00:00');
Displaying the dates in Twig with the date filter like {{ mydate|date('d.m.Y H:i:s', 'Europe/Berlin') }}
works as expected and shows 07.08.2024 14:00:00
But when I use the translation feature in combination with the ICU message format I have no idea how to set the desired timezone for displaying the dates.
my_message: the date and time is {mydate, date} {mydate, time, full}
<div>{{ my_message|trans({mydate: mydate}) }}</div>
<!-- my locale is DE -->
<div>07.08.2024 12:00:00 Koordinierte Weltzeit Uhr</div>
If I set date_default_timezone_set('Europe/Berlin')
the output of the translation is the same as before. But because I tell PHP that all my dates should have a default timezone of Europe/Berlin
the twig filter displays display the same data also. Because it converts Europe/Berlin
to Europe/Berlin
and therefore displays 12:00:00
instead of 14:00:00
.
viu-x is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.