I'm using Django 1.4.3 and Postgres 9.1.3. Here is my template where message.created_at
is a python datetime
object and it clearly tells me that the datetime object is stored in GMT as I can debug by passing e
in date
filter. The conversion to my local time which is IST is not happening though I used the block and filter given in the docs. It still renders the date time value in GMT. What am I missing?
{% load tz %}
{% localtime on %}
<div class="m_td_block">
<span>{{ message.created_at|date:"D, d M, Y e" }}</span>
<span>{{ message.created_at|time:"h:i A" }}</span>
</div>
{% endlocaltime %}
Tried the another approach too,
{% load tz %}
<div class="m_td_block">
<span>{{ message.created_at|localtime|date:"D, d M, Y e" }}</span>
<span>{{ message.created_at|localtime|time:"h:i A" }}</span>
</div>
And this is my settings,
TIME_ZONE = 'GMT'
USE_I18N = True
USE_L10N = True
USE_TZ = True
Okay. Considering these posts post#1, post#2 I'm gonna get the timezone manually from the user while signup and store it in database. And will go with
timezone.activate(request.user.timezone)
.Are you doing an
activate
to activate the local time-zone? See this.