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

Bogdan picture Bogdan · Aug 17, 2012 · Viewed 19.1k times · Source

I would like to display a formatted date in twig by applying a filter to a Unix timestamp. Is such a feature available in twig?

Answer

Florent picture Florent · Aug 17, 2012

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 -->