Home >Backend Development >PHP Tutorial >Detailed explanation of date usage in twig in symfony2.4

Detailed explanation of date usage in twig in symfony2.4

*文
*文Original
2018-01-05 17:31:391993browse

This article mainly introduces the usage of date in twig of symfony2.4, and analyzes the common methods of date and time operations in twig in the form of examples. Friends in need can refer to it. I hope it will be helpful to everyone.

Get the current time:

{{ "now"|date("Y-m-d") }} //2014-03-06

Get the time three days later

{{ "+3 day"|date('Y-m-d') }} //2014-03-09
//或者
date('+3days') //2014-03-09

Process the 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 can be used:

{{ var is empty ? "" : var|date("Y-m-d") }}

Set the time zone

{{ var|date("Y-m-d", "Europe/Paris") }} //设置时区为欧洲巴黎
{{ var|date("Y-m-d", false) }} //设置当前时区

Related recommendations:

Detailed explanation of the usage of Symfony2 controller

Detailed explanation of Symfony2 system routing

Detailed explanation of the plug-in format of Symfony2

The above is the detailed content of Detailed explanation of date usage in twig in symfony2.4. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn