Django datetimefield time in template

I have a DateTimeField in one of my models

If the template displays {{ model.datetime }} , I see:

 Aug. 13, 2013, 7:57 pm 

If the template displays {{ model.datetime.time }} , I see:

 2:57 am 

I want it to just display 7:57 pm How can I get it to use the correct time zone. I tried with model.datetime.timetz , but with the same result.

+7
python django django-templates
source share
2 answers

Try

 {{ model.datetime|date:"g:ia" }} 

If you want a different format, see the documentation here

+17
source share

If you are satisfied with the default format for your local time, replacing the call with time() method using time filter will do the job:

 {{ model.datetime|time }} 

Hth, DTK

0
source share

All Articles