bwbrowning
bwbrowning

Reputation: 6530

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.

Upvotes: 8

Views: 29363

Answers (2)

dtk
dtk

Reputation: 2536

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

{{ model.datetime|time }}

Hth, dtk

Upvotes: 1

karthikr
karthikr

Reputation: 99670

Try

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

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

Upvotes: 23

Related Questions