Django change local datetime format -
i have django app in use translation system. want django print datetime objects in local format, not in default format in print me.
example, english translation, datetime objects in format: may 14, 2015, 1:26 p.m. , want format: mm/dd/yyyy hh:mm
i.e 03/14/2015 13:26
for other langauges still month name in output in local language (like 'may 14'), , dont want that. other languages want dd/mm/yyyy hh:mm
you can set custom format different languages.
in settings:
format_module_path = [ 'mysite.formats', 'some_app.formats', ]
then create files this:
mysite/ formats/ __init__.py en/ __init__.py formats.py
see complete ref here: https://docs.djangoproject.com/en/1.8/topics/i18n/formatting/#creating-custom-format-files
then in formats.py, set want. english:
import datetime datetime_format = 'm/d/y h:i'
ref: https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#std:templatefilter-date
Comments
Post a Comment