How can I display a formatted date from a Unix timestamp in twig?

限于喜欢 提交于 2019-12-04 22:52:00

There is a filter called date.

In the following example mydate equals 1286199900:

{{ mydate|date }}           <!-- October 4, 2010 13:45 -->
{{ mydate|date('d/m/Y') }}  <!-- 04/10/2010 -->

If you just divide it by 1000 there might be an error like Failed to parse time string (1384361503.5) at position 7

I would add round function to it

{% set timestamp = (rating.ratingDate / 1000)|round(0, 'floor') %} {{timestamp|date('d. M Y')}}

I know I am playing an archaeologist but it might be helpful for someone.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!