How to display Django time after 12 hours instead of military 24

When I use the following

created = models.DateTimeField('date published')

displays a time like this

23:12:06

instead

11:12:06

I want it to display the time at 12 o’clock without 24. Also, when I click the widget now, the time is 4 minutes behind. Any help would be appreciated

+2
source share
2 answers

Django has built-in date formatting, for example:

created = DateTimeField(input_formats=['%Y-%m-%d %I:%M %p']) Here is a complete cheat sheet on how these emails work: http://blog.tkbe.org/archive/date-filter-cheat-sheet/

So, to implement a 12 hour format, use "h" or "g" depending on whether you want to have leading zeros or not

django doc: https://docs.djangoproject.com/en/dev/ref/forms/fields/#datetimefield

dev, ,

4

TIME_ZONE ?

+1

:

created = TimeField(widget=TimeInput(format='%I:%M:%S'))

created = TimeField(input_formats=('%I:%M:%S'))

% 12- , % H 24- .

django

'%H:%M:%S',     # '14:30:59'
'%H:%M:%S.%f',  # '14:30:59.000200'
'%H:%M',        # '14:30'

'%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', # '2006-10-25', '10/25/2006', '10/25/06'
'%b %d %Y', '%b %d, %Y',            # 'Oct 25 2006', 'Oct 25, 2006'
'%d %b %Y', '%d %b, %Y',            # '25 Oct 2006', '25 Oct, 2006'
'%B %d %Y', '%B %d, %Y',            # 'October 25 2006', 'October 25, 2006'
'%d %B %Y', '%d %B, %Y',            # '25 October 2006', '25 October, 2006'

'%Y-%m-%d %H:%M:%S',     # '2006-10-25 14:30:59'
'%Y-%m-%d %H:%M:%S.%f',  # '2006-10-25 14:30:59.000200'
'%Y-%m-%d %H:%M',        # '2006-10-25 14:30'
'%Y-%m-%d',              # '2006-10-25'
'%m/%d/%Y %H:%M:%S',     # '10/25/2006 14:30:59'
'%m/%d/%Y %H:%M:%S.%f',  # '10/25/2006 14:30:59.000200'
'%m/%d/%Y %H:%M',        # '10/25/2006 14:30'
'%m/%d/%Y',              # '10/25/2006'
'%m/%d/%y %H:%M:%S',     # '10/25/06 14:30:59'
'%m/%d/%y %H:%M:%S.%f',  # '10/25/06 14:30:59.000200'
'%m/%d/%y %H:%M',        # '10/25/06 14:30'
'%m/%d/%y',              # '10/25/06'

.

0

All Articles