Reputation: 386
I need to display a localized formatted date. If I use django.utils.formats.localize, the date is returned as "June 11, 2012". How could I format the date as to return "06/11/2012", with proper localization (e.g., "11/06/2012 in UK)?
I need something similar to Java's DateFormat.SHORT. Is there something analogous to that?
Upvotes: 16
Views: 12508
Reputation: 33420
Yes, there is SHORT_DATE_FORMAT.
In a template, it is possible to use it with the date filter:
{{ your_date_value|date:"SHORT_DATE_FORMAT" }}
Outside of a template, it is possible to use django.utils.formats.date_format
, as so:
from django.utils.formats import date_format
date_format(date_obj, format='SHORT_DATE_FORMAT', use_l10n=True)
Upvotes: 36