orvogq
Last Updated: February 25, 2016
·
18.87K
· andreia
Mesr

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

Say Thanks
Respond

2 Responses
Add your response

15485
0 mv6vd4ny2ecwygme2llwduz722fly4meua 5duno1e1z ymhgp99brhrg3bv00zk7nxx6pobinb1

Thanks a lot!

over 1 year ago ·
17517
None

Thank you very much!!!

over 1 year ago ·