在树枝中动态设置时区
目前,我们从UTC中的数据库中获取日期,并在视图中直接打印。 喜欢
{{createat | date(“ m/d/y”)}}}
现在,我们需要在用户时区中显示一些日期,该日期是在数据库中配置的,因此无需找到一种方法来获取用户的时区。
一种方法是,我们可以将时区传递到树枝上,并用它将日期打印为
{{createat |日期(“ m/d/y”,“欧洲/巴黎”)}}
是否有更好的方法来处理此问题?对于Ex:我们可以根据loggedin用户的时区域中的细菌中使用的默认时区设置默认时区吗?
在
$twig = new \Twig\Environment($loader);
$twig->getExtension(\Twig\Extension\CoreExtension::class)->setTimezone('Europe/Paris');
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');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论