Reputation: 931
I'm trying to get a datetime object translated to Dutch within Symfony2. Can anyone tell me how to do this.
I already tried to strftime a date => no luck :( I already tried to format the date => no luck either :(
Can anyone help on this?
If any extra info is needed, please let me know and I will add the info to this question.
I found another solution, which can be done without any extra bundles installed.
$formatter = new \IntlDateFormatter(\Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE);
//http://userguide.icu-project.org/formatparse/datetime for date formats
$formatter->setPattern("EEEE d MMMM Y");
$page['modify_date'] = $formatter->format($page['modify_date']);
$page['create_date'] = $formatter->format($page['create_date']);
Where $formatter->format(DATE), formats the date with the right pattern. This can be done from the controller.
The date can by printed from twig as follows: {{modify_date}}
Upvotes: 1
Views: 1075
Reputation: 3530
With SonataIntlBundle you can do:
{{ date_time_object | format_date }} => '1 févr. 2011'
{{ date_time_object | format_time }} => '19:55:26'
{{ date_time_object | format_datetime }} => '1 févr. 2011 19:55:26'
You can pass a locale parameter of course. Check docs
Upvotes: 0
Reputation: 31929
You could use/have a look at the KNPTimeBundle to see how it's done.
Upvotes: 1