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.
now tag displays the current date and/or time, using a format according to the given string. Such string can contain format specifiers characters as described in the date filter section.
The solution to this problem is to use UTC in the code and use local time only when interacting with end users. Time zone support is disabled by default. To enable it, set USE_TZ = True in your settings file. In Django 5.0, time zone support will be enabled by default.
DATETIME_FORMAT="%Y-%m-%d%H:%M:%S"
Try
{{ model.datetime|date:"g:i a" }}
If you want a different format, refer to the documentation here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With