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 2 years, 2 months ago
- Querying datetime aware objects in your local timezone by jayliew 11 months, 3 weeks ago
- UTC DateTime field by ludo 5 years, 8 months ago
- filter dates to user profile's timezone by Scanner 6 years, 1 month ago
- Template tags for localizing UTC times with pytz by wolever 1 year, 9 months ago
Comments