Home >Backend Development >PHP Tutorial >Analysis of date usage in twig of symfony24

Analysis of date usage in twig of symfony24

WBOY
WBOYOriginal
2016-07-29 08:57:29825browse

The example in this article describes the usage of date in twig of symfony2.4. Share it with everyone for your reference, the details are as follows:

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) }} //设置当前时区

I hope this article will be helpful to everyone in PHP program design based on the Symfony framework.

The above introduces the analysis of date usage in twig of symfony24, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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