These are chat archives for django/django

5th
Jun 2015
Valmik
@vjFaLk
Jun 05 2015 09:30
Hello, I've a bit of a time zone problem. I have set a particular time zone, and also set USE_TZ as True. It works as intended everywhere. Except when I try a datetimeobject.time tag on a template, which shows the time in UTC instead of my time zone. Using a datetimeobject tag works just fine, but I don't want to display the date, only the time. It's weird.
Mir Nazim
@mnazim
Jun 05 2015 11:44
@vjFaLk checkout django.utils.timezone. These are just wrappers around datetime package but thier output is timezone aware.
It also contains utilities for conversion to local time
A few of utilities for displaying date and time objects here documnted here https://docs.djangoproject.com/en/1.7/ref/contrib/humanize/#naturaltime
Valmik
@vjFaLk
Jun 05 2015 13:12
@mnazim Thanks for the reply. I'm actually using "django.utils.timezone" in my python code and it works as intended everywhere. Let me elaborate on the problem. Say I have a DateTimeField in my model called, "next_call". To display it's value on a template I am writing, {{ next_call }}, and this shows the correct date and time (UTC +5:30) . However, I only want to display the time. So I write, {{ next_call.time }}, and this shows the incorrect time (UTC).
I've used the different template tags in the Django documentation and they don't work with {{ next_call.time }}
Mir Nazim
@mnazim
Jun 05 2015 13:15
Have you tried {{ next_call|date:'H:M' }}
Check documentation for date templatetag to see other formating options.
Valmik
@vjFaLk
Jun 05 2015 13:52
Do you mean {{ next_call|time: 'H:M' }}? Because that doesn't work.
Mir Nazim
@mnazim
Jun 05 2015 14:45
@vjFaLk if next_call is a datetime object, date template tag will work. Just pass appropriate format specifiers.
There's also a template tag called localtime
Valmik
@vjFaLk
Jun 05 2015 15:30
Finally got it! {{ next_call|time:"P" }} did the trick
@mnazim Thanks for pointing me in the right direction :)
Mir Nazim
@mnazim
Jun 05 2015 16:43
:thumbsup: