astimezone template tag

 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

  1. UTC DateTime field by ludo 5 years, 8 months ago
  2. UTC-based astimezone filter by miracle2k 1 year, 6 months ago
  3. filter dates to user profile's timezone by Scanner 6 years, 1 month ago
  4. Template tags for localizing UTC times with pytz by wolever 1 year, 9 months ago
  5. Querying datetime aware objects in your local timezone by jayliew 11 months, 3 weeks ago

Comments

(Forgotten your password?)