Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert a date to a UNIX timestamp with Twig?

Tags:

twig

symfony

I need to convert a date to a UNIX timestamp in a Twig template:

 <li>{{ user.expired }}</li>

Is there a function in Twig to do it?

like image 716
Mark Cibor Avatar asked Feb 11 '12 16:02

Mark Cibor


1 Answers

There is the built-in date filter in Twig. You can pass any strtotime-compatible argument.

 <li>{{ user.expired | date('U') }}</li>

U is the pattern that will display the unix timestamp.

like image 72
Florian Klein Avatar answered Oct 11 '22 15:10

Florian Klein