使用 Symfony 2 本地化树枝中的日期 [英] Localize dates in twigs using Symfony 2

查看:25
本文介绍了使用 Symfony 2 本地化树枝中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要在 twig 中格式化日期,您通常使用以下内容:

To format a date in twig you usually use something like:

{{ meeting.date|date("m/d/Y") }}

现在,我必须本地化这个日期(美国 m/d/y,NL d/m/y).在树枝中执行此操作的最佳做​​法是什么?我确实使用 Symfony 2,一种解决方法是在控制器中进行翻译,但我想在树枝中这样做.

Now, I have to localize this date (US m/d/y, NL d/m/y). What would be the best practice to do this in the twig? I do use Symfony 2, a workaround would be to do the translation in the controller but i would like to do this in the twig.

推荐答案

Intl Twig 扩展?

在树枝模板中的使用:

{{ my_date | localizeddate('full', 'none', locale) }}

这篇关于使用 Symfony 2 本地化树枝中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆