Analysis of date usage in twig of symfony2.4, symfony2.4twig
This example describes the date usage in twig of symfony2.4. We will share this with you for your reference. The details are as follows:
Obtain the current time:
{{ "now"|date("Y-m-d") }} //2014-03-06
Get three days later
{"+ 3 day" | date ('Y-m-d')} // 2014-03-09 // or date ('+ 3days ') //
Process Variables in 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") }}
Set Time Zone
{Var | date ("Y-m-d", "Europe/Paris ")}} // set the time zone to Paris, Europe {var | date ("Y-m-d", false)} // set the current time zone
I hope this article will help you design PHP programs based on the Symfony framework.
Articles you may be interested in:
- Symfony2 joint query Implementation Method
- Symfony2 create page instance details
- Session and cookie usage in Symfony2
- Summary of how Symfony2 can obtain data from the database
- Symfony2 framework learning notes
- Symfony2 Study Notes plugin format Analysis
- System Route details for Symfony2 Study Notes
- A detailed explanation of the controller usage of Symfony2 learning notes
- Template usage of Symfony2 learning notes
- How to install a third-party Bundles instance in Symfony2
- Symfony2 function usage Example Analysis