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

*文
Release: 2023-03-19 10:36:01
Original
1983 people have browsed it

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
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

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!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template