How do I format time to hh:mm using Twig (Symfony)(如何使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Twig (Symfony) 将时间格式化为 hh:mm


- Flexslider 箭头未正确显示 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 400或500级别的HTTP响应 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01