How to use localized "short format" when formatting dates in Django?

I need to display a localized formatted date. If I use django.utils.formats.localize, the date is returned as "June 11, 2012." How can I format the date to return "06/11/2012" with the correct localization (for example, "11/06/2012 in the UK)?

I need something similar to Java DateFormat.SHORT . Is there something similar?

+7
source share
1 answer

Yes, there is SHORT_DATE_FORMAT .

In the template, you can use it with a date filter :

{{ your_date_value|date:"SHORT_DATE_FORMAT" }} 

Outside the template, you can use django.utils.formats.date_format , since:

 from django.utils.formats import date_format date_format(date_obj, format='SHORT_DATE_FORMAT', use_l10n=True) 
+7
source

All Articles