Skip to content

Instantly share code, notes, and snippets.

@andymckay
Created February 4, 2010 23:11
Show Gist options
  • Save andymckay/295253 to your computer and use it in GitHub Desktop.
Save andymckay/295253 to your computer and use it in GitHub Desktop.
# using dateutil (easy_install python-dateutil) allows you to
# filter dates to a particular timezone eg:
# {{ hour.object|astimezone:'US/Eastern'|date:'G'}}
from django import template
from django.conf import settings
from dateutil import zoneinfo
register = template.Library()
@register.filter(name='astimezone')
def astimezone(date, timezone):
date = date.replace(tzinfo=zoneinfo.gettz(settings.TIME_ZONE))
return date.astimezone(zoneinfo.gettz(timezone))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment