Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - Change time format for a locale

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

8 a.m.

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 proper format ?

like image 741
Pierre de LESPINAY Avatar asked Oct 26 '12 10:10

Pierre de LESPINAY


1 Answers

Apparently there is no default time format set for FR locale.

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'
like image 91
Pierre de LESPINAY Avatar answered Sep 21 '22 10:09

Pierre de LESPINAY