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

Analysis of date usage in twig of symfony24

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 08:57:29
Original
850 people have browsed it

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

Copy after login

Get the time three days later

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

Copy after login

Process the variables in twig:

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

Copy after login

date_modify usage:

{{ var|date_modify("+1 day")|date("Y-m-d") }} //2014-03-07

Copy after login

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") }}

Copy after login

Set the time zone

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

Copy after login

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.

Related labels:
Statement of this Website
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
Latest Issues
Compare JavaScript Date objects
From 1970-01-01 08:00:00
0
0
0
Select rows grouped by date
From 1970-01-01 08:00:00
0
0
0
Hive query: Convert date timestamp to date format
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template