在树枝中动态设置时区

发布于 2025-01-28 02:55:50 字数 493 浏览 0 评论 0原文

目前,我们从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文