I have L10N successfuly set up on my project, and I'm able to translate dates to the correct format. But now I need the SHORT_DATE_FORMAT
for the current locale on my templates, or in a context_processor.
Getting it from django.conf.settings
always gives me the default value, m/d/Y
.
The locale was currently set to pt_BR
, so the format should be d/m/Y
.
In [42]: settings.LANGUAGE_CODE
Out[42]: 'pt-br'
In [43]: settings.USE_L10N
Out[43]: True
In [44]: settings.SHORT_DATE_FORMAT
Out[44]: 'm/d/Y'
Any clues?
By the way, what I'm really trying to do is: get the current locale's format so I can pass it to bootstrap-datepicker plugin. It's currently using m/d/Y
and django is giving a date in the d/m/Y
format.
Java DateFormat The locale is used for specifying the region and language for making the code more locale to the user. The way of writing date is different in different regions of the world.
Date and time localization is quite an important topic when it comes to developing applications and software systems in multiple languages. Date and time are written and read in different ways in different countries.
The United States is one of the few countries that use “mm-dd-yyyy” as their date format–which is very very unique! The day is written first and the year last in most countries (dd-mm-yyyy) and some nations, such as Iran, Korea, and China, write the year first and the day last (yyyy-mm-dd).
Locale determines the human language and cultural norms used when generating a String to represent a date-time value. The time zone determines the wall-clock time of a particular region used to represent a moment on the timeline.
I had to do the following:
from django.conf import settings
from django.utils import formats
correct_format = formats.get_format("SHORT_DATE_FORMAT", lang=settings.LANGUAGE_CODE)
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