如何使用 Twig (Symfony) 将时间格式化为 hh:mm [英] How do I format time to hh:mm using Twig (Symfony)

查看:32
本文介绍了如何使用 Twig (Symfony) 将时间格式化为 hh:mm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从我的 MS SQL 数据库中检索一个时间域,例如10:30:00"(hh:mm:ss).我尝试在树枝模板中呈现它,但我只想显示10:30"部分(hh:mm).

I retrieve a timefield from my MS SQL database, for example '10:30:00' (hh:mm:ss). I try to render this in a twig template, but I only want to display the '10:30' portion (hh:mm).

我尝试使用 number_format 和 date_format 来完成这项工作,但我似乎无法完成.例如,失败的尝试是:

I've tried to get this done using both number_format and date_format, but I can't seem to get it done. For example, a failed attempt would be:

<td class="PODTIME">{{ record.PODTIME|number_format(2, ':') }}</td>

是的,这没有意义.但我找不到任何与我想要的东西很接近的东西——我想我忽略了一些东西.

Yeah that doesn't make sense. But I can't find anything even remotely close to what I want - I guess I'm overlooking something.

谢谢

推荐答案

你可以像这样使用 Twig 过滤日期:

You can use the Twig filter date like this :

{{ object.date|date('H:i:s') }}

正如在这个线程上看到的:如何渲染Twig 模板中的 DateTime 对象

As seen on this thread : How to render a DateTime object in a Twig template

这篇关于如何使用 Twig (Symfony) 将时间格式化为 hh:mm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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