1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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('UTC').localize(date).astimezone(pytz.timezone(destination))
|
More like this
- astimezone template tag by whardier 11 months, 2 weeks ago
- UTC DateTime field by ludo 4 years, 6 months ago
- Template tags for localizing UTC times with pytz by wolever 6 months ago
- Converting PDT to UTC using pytz and dateutil by simon 3 years, 6 months ago
- filter dates to user profile's timezone by Scanner 4 years, 10 months ago
Comments