Last Updated: May 02, 2019
·
31.15K
· andreia

Symfony2: Localized date string in Twig template

Enable the intl twig extension in config.yml or services.yml file:

services:
    twig.extension.intl:
        class: Twig_Extensions_Extension_Intl
        tags:
            - { name: twig.extension }

In your Twig template, you can use pre-defined (http://twig.sensiolabs.org/doc/extensions/intl.html) or custom date formats (http://userguide.icu-project.org/formatparse/datetime) with the localizeddate:

{{ blog.created|localizeddate('none', 'none', 'pt_BR', null, "cccc, d MMMM Y 'às' hh:mm aaa")}}

The pattern "cccc, d MMMM Y 'às' hh:mm aaa" will show the date in this format:

domingo, 5 janeiro 2014 às 03:00 am

2 Responses
Add your response

Thanks a lot!

over 1 year ago ·

Thank you very much!!!

over 1 year ago ·