Can someone tell me how to switch the locale date format in Symfony2?
no matter what I set in config (framework.session.default_locale), this always returns week days in english ( I would need the weekday in german language):
$start->format("D d.m.Y");
when I output the default locale it always returnes "de" BTW, no matter what I setup in the config.yml
echo \Locale::getDefault()
ADDITIONAL INFOS:
I want to be able to format the date in a way that it gets outputted correctly (meaning with correct german weekdays) on my local system AND on the live server. Tried this with strftime which uses the system's installed locales and had real troubles with it, since the locale packages have different naming schemes on the live and dev machines. There is another SO question regarding this here: PHP: why is my date formated on the server differently?
Symfony2 does not provide any date formatter in its core.
All it does is to configure the \Locale::getDefault()
value by sniffing session and request.
You have to provide some extra services to handle per locale formatting, like the SonataIntlBundle .
This bundle adds some twig filters in an extension, and provide some helpers that can be used anywhere.
Once activated, you can use them in your templates for example:
{{ my_date|format_datetime }}
More infos here: https://github.com/sonata-project/SonataIntlBundle/blob/master/Resources/doc/reference/datetime.rst
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With