'Dynamically set timezone in twig
At the moment we take the dates from database which is in UTC and directly print it in the view. Like
{{ createdAt | date("m/d/Y") }}
Now we need to display some dates in twig in users timezone which is configured in the database so no need to find a way to get the timezone of the user.
One way to do this is that we can pass the timezone to the twig and use it to print the date as
{{ createdAt | date("m/d/Y", "Europe/Paris") }}
Is there a better way to handle this? for EX: can we globally set the default timezone used in the twig based on timezone of the loggedin user?
Found something in here but not sure how it should be implemented
$twig = new \Twig\Environment($loader);
$twig->getExtension(\Twig\Extension\CoreExtension::class)->setTimezone('Europe/Paris');
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
