1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | from django import template
from django.conf import settings
import pytz
register = template.Library()
@register.filter
def astimezone(date, destination=None):
if not destination:
destination = settings.TIME_ZONE
if date.tzinfo:
return date.astimezone(pytz.timezone(destination))
else:
return pytz.timezone(settings.TIME_ZONE).localize(date).astimezone(pytz.timezone(destination))
|
More like this
- UTC DateTime field by ludo 5 years, 10 months ago
- UTC-based astimezone filter by miracle2k 1 year, 7 months ago
- filter dates to user profile's timezone by Scanner 6 years, 2 months ago
- Template tags for localizing UTC times with pytz by wolever 1 year, 10 months ago
- Querying datetime aware objects in your local timezone by jayliew 1 year ago
Comments