bwbrowning bwbrowning - 2 months ago 8
Python Question

Django datetimefield time in template

I have a

DateTimeField
in one of my models

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

Aug. 13, 2013, 7:57 p.m.


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

2:57 am


I want it to just display
7:57 p.m.
How can I get it to use the correct timezone. I have tried with
model.datetime.timetz
as well but with the same result.

Answer

Try

{{ model.datetime|date:"g:i a" }}

If you want a different format, refer to the documentation here