Take the 2-minute tour ×

Inside my app I use normal datetime objects. In my template:

{% load tz %}


{% timezone "Europe/Paris" %}
{% endtimezone %}

This prints something like this:

Dec. 5, 2012, 4 p.m.
Dec. 5, 2012, 3 p.m.

So the timezone filter adjusts the date but timezone tag DOES NOT.

Why is that? And how I can use tag properly? My goal is to adjusts all datetimeobjects in whole template without adding filter to every datetimeobject printed in template.


I tried to make my dateobjects timezone aware:

offset = timezone('Europe/London')

But that didnt help - still of the previous code but with tz aware datetimeobject is:

Dec. 5, 2012, 4 p.m.
Dec. 5, 2012, 3 p.m.

solved: I had a mistake in above code - should be:

offset = timezone('Europe/London')
datetimeobj = datetimeobj.replace(tzinfo=offset)
share|improve this question
I notice you have import tz where the documentation has load tz is that intentional? –  Serdalis Jan 31 '13 at 21:29
I my original code I have load, sory, I will edit this –  user606521 Jan 31 '13 at 22:04
datetimeobj.replace(tzinfo=zone) is incorrect, use zone.localize(datetimeobj, is_dst=None) instead (assuming datetimeobj is a naive datetime object) or zone.normalize(datetimeobj.astimezone(zone)) (assuming timezone-aware datetime object). See pytz.sourceforge.net –  J.F. Sebastian Feb 1 '13 at 18:11
but it works for me... –  user606521 Feb 2 '13 at 0:09
read the link I provided to understand when, how, and why it breaks. –  J.F. Sebastian Feb 2 '13 at 9:24

1 Answer 1

up vote 3 down vote accepted

You say you use "normal datetime objects", but they are apparently timezone naive instead of timezone aware.

The timezone filter "forces conversion of a single value to an arbitrary timezone" while the timezone tag just sets the current timezone until the endtimezone tag.

Your datetimeobject is timezone naive and the timezone filter will convert it to a timezone aware datetime with the default timezone and then represent it in the timezone given to the filter.

share|improve this answer
I tried to convert datwtimeobjects to be tz aware but that didnt help - see my edited post –  user606521 Feb 1 '13 at 7:56
Sorry my mistake it should be datetimeobj = datetimeobj.replace(tzinfo=offset) - it works now, thanks –  user606521 Feb 1 '13 at 10:00

Your Answer


