Analysis of date usage in twig of symfony2.4 _ php instance

Source: Internet
Author: User
This article mainly introduces the date usage in twig of symfony2.4, and analyzes common methods of date and time operations in twig Based on the instance form, you can refer to the following example to describe 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.