I have a DateTimeField in my model.
When I add this field to admin.py , then the format shows as 4:00 pm , how can this be changed to 16:00?
creation_date = models.DateTimeField(auto_now_add=True,)
If I do this
def time(self):
return self.creation_date.timezone().strftime('%Y-%m-%d %H:%M:%S')
that time field is not sorted
You can override the format with the DATETIME_FORMAT
setting: https://docs.djangoproject.com/en/4.2/ref/settings/#datetime-format
Default: 'N j, Y, P' (e.g. Feb. 4, 2003, 4 p.m.)
The default formatting to use for displaying datetime fields in any part of the system. Note that if USE_L10N is set to True, then the locale-dictated format has higher precedence and will be applied instead. See allowed date format strings.