In this paper, we mainly introduce the date usage in the twig of symfony2.4, and analyze the common methods for date and time operation in Twig with the example form. Need friends can refer to, hope to help you.
Get current time:
{"Now" |date ("Y-m-d")}}//2014-03-06
Get three days after the time
{{"+3 Day" |date (' y-m-d ')}}//2014-03-09//or date (' +3days ')//2014-03-09
To handle the variables in the twig:
{{var|date ("y-m-d")}}//2014-03-06
Date_modify usage:
{{var|date_modify ("+1 Day") |date ("Y-m-d")}}//2014-03-07
If the var variable is empty and the default value is set, the following syntax is available:
{{var is empty?} "": Var|date ("y-m-d")}}
Setting the time zone
{{var|date ("y-m-d", "Europe/paris")}}//Set time zone for Europe Paris {{var|date ("y-m-d", False)}}//Set current time zone
Related recommendations:
Detailed description of Symfony2 controller usage
Detailed system routing for Symfony2
Detailed Symfony2 plug-in format