Date and Time setting in Django
My Django (5) instance adds am and pm to times, but here we are used to 24h clocks. So I wish to change this behavior.
In my model I have this field: added_date = models.DateTimeField("date added")
, it currently displays as: April 23, 2025, 10:01 a.m.
I have tried many things now to change this, including these settings:
# Internationalization
# https://docs.djangoproject.com/en/5.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Europe/Amsterdam'
USE_I18N = False
USE_TZ = True
USE_L10N = False
DATETIME_FORMAT = "c"
I have also tried changing TIME_FORMAT and DATE_FORMAT and various formatting string like "DATE_FORMAT = "%Y-%m-%d"
and other things specified here: https://docs.djangoproject.com/en/5.2/ref/settings/#datetime-format, but the only thing that changed anything so far was to do {{ dataset.added_date|time:"H:i" }} in the html.
But I'd prefer to just set it in 1 place. How to do that?
Brother, you can change the setting.
If this doesn't work, you can set the format directly to the template.
{{ added_date|date:"Y-m-d H:i" }}
which you show this: 2025-04-24 06:26
in the 24 Hr format.