Django - change time format for locale

I am working on a project that uses l10n.
If I set the locale to EN and try to display the time (08:00), I get:

8 am 

If I set the locale to FR, I get:

 08:00:00 

But it should be something like:

 8h 

Why am I getting this format? How can I get the correct format?

+7
source share
2 answers

There seems to be no default time format for the FR format.

What you can do is configure the format module :

 # myproject/settings.py FORMAT_MODULE_PATH = 'myproject.formats' 

Create it:

 myproject/ formats/ __init__.py fr/ __init__.py formats.py 

And define the French format:

 # myproject/formats/fr/formats.py TIME_FORMAT = 'G:i' 
+10
source

I do not believe that you can change the format if you use localization from my understanding of this: https://docs.djangoproject.com/en/dev/topics/i18n/timezones/ .

Is USE_L10N = True ? If so, it will override the settings.TIME_FORMAT and settings.TIME_INPUT_FORMATS values: https://docs.djangoproject.com/en/dev/ref/settings/#time-format

You can write your own "context processor" or "localization filter" based on the selected language.

+1
source

All Articles